Skip to content

Instantly share code, notes, and snippets.

@krackers
krackers / easysql.js
Created October 26, 2019 01:24 — forked from konsumer/easysql.js
HTML5 Promise-based WebSQL query convenience-function
// https://github.com/Philzen/WebSQL-Polyfill
// https://github.com/jakearchibald/es6-promise
/**
* Usage:
* var db = new DB('demo', '1.0', 'Demo', 2 * 1024 * 1024);
* db.query('SELECT * FROM mytable')
* .then(function(res){
* console.log(res.rows);
* }, function(err){
var BVT = function(width, depth, init, elems) {
this._width = width;
this._depth = depth;
this._leaf = depth === 1;
this._shift = (this._depth - 1) * Math.round(Math.log(width) / Math.log(2));
this._himask = this._width - 1;
this._lomask = Math.pow(2, this._shift) - 1;
this._elems = elems;
@krackers
krackers / python-bash-wrapper.py
Created January 26, 2020 04:24 — forked from DarwinAwardWinner/python-bash-wrapper.py
Put bash cluster setup code and python script in a single file
#!/bin/bash
# -*- mode:python -*-
#PBS -l nodes=1:ppn=8,mem=30gb
''''/bin/true
# This is bash code to set up the environment
echo "Hello from bash!"
echo "Args are: $@"
# Bash setup code ends here
python - "$@" <<EOF
''' # Python starts here '''
#!/bin/sh
# -*- mode:R -*-
#PBS -l nodes=1:ppn=8,mem=30gb
'\' >/dev/null 2>&1 || true
# This is bash code to set up the environment
echo "Hello from bash!"
echo "Args are: $@"
@krackers
krackers / userChrome.css
Created February 19, 2020 00:03 — forked from tjespe/userChrome.css
Make Firefox Quantum look like Chrome
/* Should be put at
* `$FIREFOX_PROFILE/chrome/userChrome.css`
* e.g.:
* `/Users/tordjohanespe/Library/Application%20Support/Firefox/Profiles/l2hbvytn.dev-edition-default-1510516302187/chrome/userChrome.css`
*/
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
@-moz-document url(chrome://browser/content/browser.xul) {
#TabsToolbar {
margin-top: -3px !important;
margin-bottom: -2px !important
@krackers
krackers / gist:a72fd7709b5b1b9a7b4e765fdbc017a1
Created May 17, 2020 02:08 — forked from ingramchen/gist:e2af352bf8b40bb88890fba4f47eccd0
ffmpeg convert gif to mp4, for best cross browser compatibility
### Full command line options
```
ffmpeg -f gif -i FOO.gif -pix_fmt yuv420p -c:v libx264 -movflags +faststart -filter:v crop='floor(in_w/2)*2:floor(in_h/2)*2' BAR.mp4
```
### Notie
* output mp4 is encoded with h264, support Firefox/Chrome/Safari in Windows, Mac OSX, Android, and iOS.
#!/usr/bin/env python3
import z3
import pprint
# 9x9 matrix of integer variables
X = [ [ z3.Int("x_%s_%s" % (i+1, j+1)) for j in range(9) ]
for i in range(9) ]
# each cell contains a value in {1, ..., 9}
cells_c = [ z3.And(1 <= X[i][j], X[i][j] <= 9)
@krackers
krackers / dht-walkthrough.md
Created June 7, 2020 18:34 — forked from gubatron/dht-walkthrough.md
DHT walkthrough notes

DHT Walkthrough Notes

I've put together these notes as I read about DHT's in depth and then learned how the libtorrent implementation based on the Kademlia paper actually works.

What problem does this solve?

400,000,000,000 (400 billion stars), that's a 4 followed by 11 zeros. The number of atoms in the universe is estimated to be around 10^82. A DHT with keys of 160 bits, can have 2^160 possible numbers, which is around 10^48

#import <Foundation/Foundation.h>
typedef uint64_t CGSSpace;
typedef uint64_t CGSManagedDisplay;
typedef int CGSConnection;
typedef enum _CGSSpaceSelector {
kCGSSpaceCurrent = 5,
kCGSSpaceOther = 6,
kCGSSpaceAll = 7