Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
jacqueswww / fix_pdf.sh
Created September 14, 2017 16:09
Fix python PDFLib segmentation fault.
cp original.pdf bak.pdf
gs -o original.pdf -sDEVICE=pdfwrite bak.pdf
@jacqueswww
jacqueswww / reverse_replace_x_newlines.py
Created September 25, 2017 12:27
Replace newlines in a string, but allow x newlines to remain at the beginning.
def remove_extra_newlines(input_str, newlines_left=3):
number_of_newlines = input_str.count('\n')
if number_of_newlines > newlines_left:
amount_to_strip = number_of_newlines - newlines_left
return input_str[::-1].replace('\n', ' ', amount_to_strip)[::-1]
else:
return input_str
@jacqueswww
jacqueswww / hyperfido.txt
Created October 5, 2017 08:38 — forked from rkennesson/hyperfido.txt
Hyperfido instructions
HyperFido - FIDO U2F Security Key
By Jonathan Williams
https://www.amazon.com/review/R1MX4254RVC97T/ref=cm_cr_dp_cmt?ie=UTF8&ASIN=B00WIX4JMC&channel=detail-glance&nodeID=541966&store=pc#wasThisHelpful
This HyperFIDO U2F key is small enough to keep in your pocket or purse at all times and never worry about it. It worked great after getting a fast reply from HyperSECU support about the linux udev rules needed (I don't use windows). I had it set up very quickly with Google services and it worked flawlessly. Hopefully, more services will support U2F in the future.
If you are wondering, here are the udev rules their awesome support recommended. I created a file /etc/udev/rules.d/96-hyperfido.rules and used the first example below because thankfully, I do not have to deal with systemd. If you are unfortunate enough to have to use systemd, please use the second example.
Example 1
@jacqueswww
jacqueswww / pyethereum_set_trace_logging.py
Created November 15, 2017 11:52
Pyethereum: how to get useful verbose debug output.
from ethereum.slogging import configure_logging
configure_logging(':trace')
@jacqueswww
jacqueswww / spotify_keybindings
Last active February 26, 2018 15:49 — forked from jbonney/spotify_keybindings
Spotify - Linux key bindings. From XFCE / Ubuntu keyboard shortcuts configuration, assign the control command to their key.http://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" XF86AudioPlay
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop" XF86AudioStop
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" XF86AudioNext
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" XF86AudioPrevious
@jacqueswww
jacqueswww / test_contract_pyethereum.py
Created March 25, 2018 20:54
Test a vyper contract with pyethereum.
from ethereum.tools import tester
from vyper import compiler
def test_merkle_proof_contract():
tester.languages['vyper'] = compiler.Compiler()
s = tester.Chain() # initialize test chain
contract_code = open('merkleproof.v.py').read() # get source code
contract = s.contract(contract_code, language='vyper') # compile code
@jacqueswww
jacqueswww / pre_vdb_ipdb.py
Last active September 25, 2019 16:20
Pretty Damn awful, PyEVM Virtual Machine debugger. Using a custom opdcode set in Vyper ;)
def debug_opcode(computation):
print('YOUR ARE HERE!')
import ipdb; ipdb.set_trace()
import evm
from evm.vm.opcode import as_opcode
from vyper.opcodes import opcodes as vyper_opcodes
from evm.vm.forks.byzantium.computation import ByzantiumComputation
opcodes = ByzantiumComputation.opcodes.copy()
# Module for codegen. Currently most codegen lives in
# parser/parser_utils.py and can slowly be migrated here as
# type-checking code gets factored out.
from vyper.exceptions import (
InvalidLiteralException,
TypeMismatchException,
StructureException
)
from vyper.types import (
[seq,
[return,
0,
[lll,
[seq,
[mstore, 28, [calldataload, 0]],
[mstore, 32, 1461501637330902918203684832716283019655932542976],
[mstore, 64, 170141183460469231731687303715884105727],
[mstore, 96, -170141183460469231731687303715884105728],
[mstore, 128, 1701411834604692317316873037158841057270000000000],
_______________________________________________________________ test_struct_return_abi ________________________________________________________________
data_type = '(int128,bool)', data_value = (1, True)
def abi_sub_tree(data_type, data_value):
if data_type is None:
return ABITypedData([None, data_value])
try:
> base, sub, arrlist = data_type