Skip to content

Instantly share code, notes, and snippets.

View chewxy's full-sized avatar
💭
Test Status. Do not upvote

Chewxy chewxy

💭
Test Status. Do not upvote
View GitHub Profile
@chewxy
chewxy / queryLang.sql
Created October 31, 2012 14:33
Used to query StackOverflow's data explorer. Originally written by Guillermo Winkler. Adapted by me
SELECT
Questions.CreationDate,
Questions.Title,
Tags.TagName,
Answers.CreationDate as ResponseDate,
datediff(minute, Questions.CreationDate,
Answers.CreationDate) as ResponseTime,
cast(DATEPART(hour, Questions.CreationDate) as int) as ResponseHour
FROM Posts Questions
join Posts Answers on Answers.id = Questions.AcceptedAnswerId
import math
class Monad(object):
__slots__=['value']
def bind(self, f):
if type(self) is List and type(self.value) is list:
return self._bind(f)
elif type(self) is Value and type(self.value) is list:
# transform it into a List(Value)
@chewxy
chewxy / getJSEBNF.py
Created September 3, 2014 04:22
Gets the EBNF from the ECMAScript 5.1 spec
from bs4 import BeautifulSoup
import requests
r = requests.get('http://www.ecma-international.org/ecma-262/5.1/')
soup = BeautifulSoup(r.text)
sections = ('sec-A.1', 'sec-A.2', 'sec-A.3', 'sec-A.4', 'sec-A.5')
appendix = []
for s in sections:
@chewxy
chewxy / gist:02159093814794eb18d8
Created August 17, 2014 13:49
variadic functions in ASM
.LFB0:
pushq %rbp
movq %rsp, %rbp
subq $64, %rsp
movl %edi, -180(%rbp)
movq %rdx, -160(%rbp)
movq %rcx, -152(%rbp)
movq %r8, -144(%rbp)
movq %r9, -136(%rbp)
testb %al, %al
@chewxy
chewxy / gist:17e6920b608208647a74
Created August 7, 2014 22:47
Running arbitrary code in Python
# Sorry for using Python 2.7
from ctypes import *
import os, sys
argv = int(sys.argv[1])
argv2 = int(sys.argv[2])
PROT_NONE = 0x0
PROT_READ = 0x1
PROT_WRITE = 0x2
@chewxy
chewxy / colourhist.py
Created February 12, 2014 17:41
Quick and Dirty Colour Histogram of a masked image in OpenCV
import cv2
import numpy as np
import matplotlib.pyplot as plt
im = cv2.imread('IMG_3545S.JPG')
# convert to greyscale for easy thresholding
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# get a threshold - basically splits the image into black and white