Skip to content

Instantly share code, notes, and snippets.

@jimjh
jimjh / gevent_sleep.py
Last active November 23, 2018 18:31
gevent_sleep.py
"""Usage: start `nc -l 127.0.0.1 8080`, then run this script."""
from __future__ import print_function
import socket
import time
if __name__ == '__main__':
n1 = time.clock()
n2 = time.time()
@jimjh
jimjh / Pipfile.yaml
Created September 5, 2018 05:43
Pipfile example
# pip-tools example
requests~=2.10
# Pipfile example
[packages]
requests = '~=2.10'
@jimjh
jimjh / luigi.py
Created September 5, 2018 05:32
example of shading
# luigi 1.x is renamed to luigi1
from luigi1 import Task as Task1
# luigi 2.x is imported as usual
from luigi import Task
@jimjh
jimjh / requirements.yaml
Created September 5, 2018 05:28
requirements.txt example for deps post
# compiled requirements.txt, or Pipfile.lock (aka "lock file")
certifi==2018.8.24 # via requests
chardet==3.0.4 # via requests
click==6.7 # via flask
flask==1.0.2
idna==2.7 # via requests
itsdangerous==0.24 # via flask
jinja2==2.10 # via flask
markupsafe==1.0 # via jinja2
requests==2.19.1
@jimjh
jimjh / track.js
Created July 19, 2013 14:15
Event tracking with Google Analytics and LaunchRock.
function conversion(){
var tracker = _gat._createTracker('UA-XXXXXXX-X');
tracker._trackEvent('Users', 'Sign Up');
}
$('.LR-sign-up-submit').click(conversion);
$('.LR-sign-up-input').keypress(function(c) {
(13 == c.which) && conversion();
});
@jimjh
jimjh / bouncy.rs
Created June 19, 2017 18:08
Project Euler P112
pub fn search_bouncy() -> i32 {
//! procedural implementation
let mut n = 100;
let mut hit = 0.0;
let mut total = 100.0;
while hit / total < 0.99 {
n = n + 1;
if is_bouncy(n) {
hit = hit + 1.0;
}
@jimjh
jimjh / resize.sh
Created April 8, 2016 00:48
Resize docker terminals to a sensible width/height
#!/bin/bash
# Usage: ./resize.sh [container ID]+
set -o errexit
set -o nounset
set -o pipefail
sudo apt-get -qqy install jq socat
while [[ -n ${1:-''} ]]; do
@jimjh
jimjh / Main.java
Created January 15, 2014 17:53
polymorphism
public class Main {
// which method does it invoke?
public static void main(String[] args) {
Object o = "this is a string";
asLong(o);
}
public static void asLong(String s) {
System.out.println("string");
@jimjh
jimjh / libgit2-fpm.sh
Last active December 29, 2015 19:41
libgit2-fpm.sh
#!/bin/bash
# cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr --build .
# make
# make install DESTDIR=~/tmpinstalldir
fpm -f \
-s dir \
-t deb \
-n libgit2 \
-v 0.23.4ppa1 \
-C ~/tmpinstalldir \
@jimjh
jimjh / mongoid_query.rb
Created July 25, 2013 13:39
mongoid complex query
require 'mongoid'
require 'fabrication'
Mongoid::Config.load_configuration({
sessions: {
default: {
hosts: ['localhost:27017'],
database: 'local'
}
}