Skip to content

Instantly share code, notes, and snippets.

class Tree(object):
def __init__(self, cargo, left=None, right=None):
self.cargo = cargo
self.left = left
self.right = right
def __str__(self):
return str(self.cargo)
#Traversing through the tree
from multiprocessing import Pool, cpu_count
import time
from random import randint
def roll(dice=1, sides=6):
try:
return [randint(1, sides) for i in range(dice)]
except:
return []
REQUEST_SESSIONS = {
"api": requests.Session(),
"probe": requests.Session()
}
REQUEST_SESSIONS["api"].headers["User-Agent"] += " +http://git.io/cso_malucrawl"
from uuid import uuid1
from time import time
def main():
test = dict()
limit = 10 ** 10
while limit:
limit -= 1
x = {n:uuid1().hex for n in range(15)}
if len(set(x.values())) != len(x.keys()):
@graingert
graingert / README.md
Created April 13, 2016 14:44 — forked from smileart/README.md
My ZSH Theme — Agnoster Mod

My modified fork of agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

Compatibility

@graingert
graingert / dataURItoBlob.js
Created April 27, 2016 14:05 — forked from davoclavo/dataURItoBlob.js
Convert dataURI to Blob so large images do not crash the browser. Based on: http://stackoverflow.com/questions/10412299 and http://stackoverflow.com/questions/6850276
function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to an ArrayBuffer
var arrayBuffer = new ArrayBuffer(byteString.length);
var _ia = new Uint8Array(arrayBuffer);
@graingert
graingert / gist:bf23f6f4193679272307cc2c1ac1e763
Created May 15, 2017 17:12 — forked from colin-kiegel/gist:b35d278d6ed5251dfa85
regex replace multi-line + in multiple files
$FILES="*.rs"
$REGEX="s#(.*)\n(.*)/\2\n\1/"
find . -name "$FILES" | xargs perl -0777 -pi -e '$REGEX'
# flag: -0777 tells perl to read the file as a whole
# replace '-pi' with '-pi.bak' to create backups
@graingert
graingert / Dockerfile
Created June 26, 2017 12:43 — forked from tabiodun/Dockerfile
Dockerfile for tabiodun/selenium-chrome-headless
FROM selenium/node-base:3.4.0-dysprosium
USER root
ARG CHROME_VERSION="google-chrome-beta"
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update -qqy \
&& apt-get -qqy install \
map.on('click', function(event){
var x1_wgs;
var y1_wgs;
async function ajax(x,y){
const data = $.ajax({
url:'/geocoding/egsa_2_wgs.php?x='+x+'&y='+y,
async:true,
type:'GET',
@graingert
graingert / repl.scala
Created December 20, 2017 17:12 — forked from fedesilva/repl.scala
Voldemort types in scala
f@omoikane:~$ scala
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :load Workshop/mine/scala-misc/voldemort.scala
Loading Workshop/mine/scala-misc/voldemort.scala...
defined module Dungeon
scala> val nemesis = Dungeon curse "fedesilva"