sign

Fastest way to flip the sign of a double / float in C

孤街醉人 提交于 2019-11-29 18:17:21
问题 What is the fastest way to flip the sign of a double (or float) in C? I thought, that accessing the sign bit directly would be the fastest way and found the following: double a = 5.0; *(__int64*)&a |= 0x8000000000000000; // a = -5.0 float b = 3.0; *(int*)&b |= 0x80000000; // b = -3.0 However, the above does not work for negative numbers: double a = -5.0; *(__int64*)&a |= 0x8000000000000000; // a = -5.0 回答1: Any decent compiler will implement this bit manipulation if you just prepend a

PDFBox 1.8.10: Fill and Sign PDF produces invalid signatures

萝らか妹 提交于 2019-11-29 14:14:18
I fill (programatically) a form (AcroPdf) in a PDF document and sign the document afterwards. I start with doc.pdf, create doc_filled.pdf, using the setFields.java example of PDFBox. Then I sign doc_filled.pdf, creating doc?filled_signed.pdf, using some code, based on the signature examples and open the pdf in the Acrobat Reader. The entered Field data is visible and the signature panel tells me "There are errors in the formatting or information contained in this signature (The signature byte array is invalid)" So far, I know that: the signature code applied alone (i.e. directly creating some

Bouncycastle PGP decrypt and verify

孤人 提交于 2019-11-29 13:07:09
问题 I'm trying to decrypt and verify a PGP message using the java BouncyCastle libraries, but am running into issues, complaining about premature ends of PartialInputStream. I know the encrypt works fine, because I can decrypt and verify messages created with the encrypt function using gpg on the command line. Here's the code: public static void signEncryptMessage(InputStream in, OutputStream out, PGPPublicKey publicKey, PGPPrivateKey secretKey, SecureRandom rand) throws Exception { out = new

一次使用scrapy的问题记录

こ雲淡風輕ζ 提交于 2019-11-29 11:46:04
前景描述: 需要获取某APP的全国订单量,及抢单量。由于没有全国的选项所以只能分别对每一个城市进行订单的遍历。爬虫每天运行一次,一次获取48小时内的订单,从数据库中取出昨天的数据进行对比,有订单被抢则更新,无则不操作。(更新逻辑在这里不重要,重要的是爬取逻辑)。每个订单有发布时间,根据发布时间判断,在48小时外的就停止爬取,开始爬取下一个城市。 先看第一版: Copy #spider 构造一些请求参数,此处省略 从配置中读取所有城市列表 cities = self.settings[‘CITY_CH’] end_signal为某个城市爬取完毕的信号, self.end_signal = False for city in cities: # 通过for循环对每个城市进行订单爬取 post_data.update({‘locationName’:city}) count = 1 while not self.end_signas: post_data.update({‘pageNum’:str(count)}) data = ‘’.join(json.dumps(post_data, ensure_ascii=False).split()) sign = MD5Util.hex_digest(api_key + data + salt).upper() params = {

AcWing 114. 国王游戏(贪心)

六眼飞鱼酱① 提交于 2019-11-29 08:10:30
传送门 #include <bits/stdc++.h> using namespace std; constexpr int base = 1000000000; constexpr int base_digits = 9; struct bigint { // value == 0 is represented by empty z vector<int> z; // digits // sign == 1 <==> value >= 0 // sign == -1 <==> value < 0 int sign; bigint() : sign(1) {} bigint(long long v) { *this = v; } bigint &operator=(long long v) { sign = v < 0 ? -1 : 1; v *= sign; z.clear(); for (; v > 0; v = v / base) z.push_back((int) (v % base)); return *this; } bigint(const string &s) { read(s); } bigint &operator+=(const bigint &other) { if (sign == other.sign) { for (int i = 0, carry

Javascript: convert a (hex) signed integer to a javascript value

删除回忆录丶 提交于 2019-11-29 07:06:05
I have a signed value given as a hex number, by example 0xffeb and want convert it into -21 as a "normal" Javascript integer. I have written some code so far: function toBinary(a) { //: String var r = ''; var binCounter = 0; while (a > 0) { r = a%2 + r; a = Math.floor(a/2); } return r; } function twoscompl(a) { //: int var l = toBinaryFill(a).length; var msb = a >>> (l-1); if (msb == 0) { return a; } a = a-1; var str = toBinary(a); var nstr = ''; for (var i = 0; i < str.length; i++) { nstr += str.charAt(i) == '1' ? '0' : '1'; } return (-1)*parseInt(nstr); } The problem is, that my function

浅谈HttpRunner 做Http接口自动化测试

眉间皱痕 提交于 2019-11-29 06:34:51
HttpRunner 框架 简介 HttpRunner 是一款面向 HTTP(S) 协议的通用测试框架,只需编写维护一份 YAML/JSON 脚本,即可实现自动化测试、性能测试、线上监控、持续集成等多种测试需求 【 引用作者简述 】 相关链接 HttpRunner中文使用文档 Github_HttpRunner 作者博客-DebugTalk 框架对比 框架 最新版本 开发语言 支持语言 持续集成 拓展难度 性能测试 数据分离 推广门槛 其它特性 Robot Framework 3.1.2 python python/java 是 高 不支持 支持 低 自带wx的GUI,可支持界面化或命令操作,可支持web UI自动化seleniumLibrary HttpRunner 2.0 python python 是 中 支持 支持 高 脚本化、有完善易阅读报告输出 Jmeter 5.1.1 java java 是 高 支持 支持 低 更偏向于接口性能;做功能测试,用例维护管理难 HttpRunner 模块化架构 关于HttpRunner框架详情,在此不做过多介绍,本次内容主要以实战为主 HttpRunner 环境安装 因 python2.7版本已停止更新,不在维护,大部分相关开源项目与库已不再对 python2.x 版本的支持,所以此处用 Python3.6 + HttpRunner 1

How to sign pdf in Java using pdfbox

妖精的绣舞 提交于 2019-11-29 03:55:15
I am trying to sign pdf using pdfbox libraries. I have stuck now and realy need a help. This is my code: private static void signPdf(PDDocument document) throws Exception { PDSignature sig = new PDSignature(); sig.setFilter(COSName.ADOBE_PPKLITE); sig.setSubFilter(COSName.ADBE_PKCS7_DETACHED); sig.setByteRange(new int[] {'a','a','a','a'}); sig.setContents(new byte[]{(byte) 23, (byte) 23, (byte) 23, (byte) 23}); SignatureOptions options = new SignatureOptions(); document.addSignature(sig, new SignatureInterface() { public byte[] sign(InputStream content) throws SignatureException, IOException {

08.字符串转换位整数

此生再无相见时 提交于 2019-11-29 03:20:28
题目: 提交: class Solution { public int myAtoi(String str) { str = str.trim(); if (str == null || str.length() == 0) return 0; // + - 号 char firstChar = str.charAt(0); int sign = 1; int start = 0; long res = 0; if (firstChar == '+') { sign = 1; start++; } else if (firstChar == '-') { sign = -1; start++; } for (int i = start; i < str.length(); i++) { if (!Character.isDigit(str.charAt(i))) { return (int) res * sign; } res = res * 10 + str.charAt(i) - '0'; if (sign == 1 && res > Integer.MAX_VALUE) return Integer.MAX_VALUE; if (sign == -1 && res > Integer.MAX_VALUE) return Integer.MIN_VALUE; } return

python - 对接微信支付(PC)和 注意点

社会主义新天地 提交于 2019-11-29 01:56:09
注:本文仅提供 pc 端微信扫码支付(模式一)的示例代码。   关于对接过程中遇到的问题总结在本文最下方。   参考: 官方文档 ,      https://blog.csdn.net/lm_is_dc/article/details/83312706 一。wxpay_settings.py (配置基本参数和创建订单时必要的方法,如 随机生成字符串,加密签名,生成支付二维码等) # encoding: utf-8 import random import os import time import requests import hashlib from random import Random import qrcode from bs4 import BeautifulSoup from appname import settings APP_ID = "" # 公众账号appid MCH_ID = "" # 商户号 API_KEY = "" # 微信商户平台(pay.weixin.qq.com) -->账户设置 -->API安全 -->密钥设置,设置完成后把密钥复制到这里 UFDODER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder" # url是微信下单api NOTIFY_URL = "http://xxx