Skip to content

Instantly share code, notes, and snippets.

@MLLeKander
MLLeKander / function.go
Last active August 29, 2015 14:00
Fuck goto (sometimes)
// Reduce argument
z := 1.0
for x >= 3 {
x = x - 1
z = z * x
}
for x < 0 {
if x > -1e-09 {
return handleSmallGammaX(x,z)
}
func smallOkay(x, z float64) (float64, float64, bool) {
for x < 0 {
if x > -1e-09 {
return x, z, true
}
z = z / x
x = x + 1
}
for x < 2 {
if x < 1e-09 {
stmt = make_unique<ast::Print>();
if (!SYNTAX_OPTIONAL_ADVANCE_KEYWORD(lex::KW_endl)) {
MUST_PARSE(parse_expr<CK_Regular>(r, lr, f, it,
stmt->as_a<ast::Print>().expr));
}
if (SYNTAX_OPTIONAL_ADVANCE_KEYWORD(lex::KW_endl)) {
stmt->as_a<ast::Print>().endl = true;
}
SYNTAX_ADVANCE(lex::TK_Semicolon);
break;
@MLLeKander
MLLeKander / gist:a2d8431bd9dca02e8503
Created May 5, 2014 04:11
Achievement unlocked: Make the JVM segfault
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00002b68b0bb0590, pid=7115, tid=47728637200128
#
# JRE version: OpenJDK Runtime Environment (7.0_51) (build 1.7.0_51-b00)
# Java VM: OpenJDK 64-Bit Server VM (24.45-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libc.so.6+0x149590] __nss_hosts_lookup+0x104b0
#
interface Function<A, B> {
public B call(A arg);
}
interface Functor<F, A> {
public <B> F<B> fmap(Function<A, B> f);
}
class List<A> implements Functor<List, A> {
private ArrayList<A> lst = new ArrayList<A>();
@MLLeKander
MLLeKander / Sieve.java
Created October 19, 2014 22:12
Sieve of Eratosthenes Implementation
class Sieve {
public static void main(String[] args) {
int MAX_VALUE = 10000;
boolean[] isComposite = new boolean[MAX_VALUE];
isComposite[1] = isComposite[0] = true;
for (int i = 2; i*i < MAX_VALUE; i++) {
if (!isComposite[i]) {
for (int o = i*2; o < MAX_VALUE; o += i) {
isComposite[o] = true;
}
@MLLeKander
MLLeKander / autothresh_book.c
Last active August 29, 2015 14:13
Autothresholding
char mean(char* img, int dim) {
int sum = 0;
for (int i = 0; i < dim; i++) {
sum += img[i];
}
return (char)(sum/(double)dim);
}
int autothresh_book(char* img, int dim) {
int hiCount, loCount, hiSum, loSum;
char T = mean(img, dim), oldT = 0;
@MLLeKander
MLLeKander / main.py
Last active August 29, 2015 14:13 — forked from mr1337357/main.py
#too short to license, so public domain
from wavegen import wavegen
from sys import stdout
import random
def tochar(sample):
return chr(int(sample * 127 + 127))
a = wavegen(440)
ash = wavegen(466.16)
b = wavegen(493.88)
@MLLeKander
MLLeKander / streams
Last active September 16, 2016 18:00
Script to list Twitch streams
#!/usr/bin/env python2
import urllib2, json
from multiprocessing.dummy import Pool as ThreadPool
def auth_urlopen(url):
request = urllib2.Request(url)
request.add_header('Client-ID','8vbhkriv9mcwqfhar3zqfuckvcptbnq')
request.add_header('Accept','application/vnd.twitchtv.v2+json')
return urllib2.urlopen(request)
abstract class Person implements Comparable<Person> {
protected String lastName, firstName;
public Person(String lastName, String firstName) {
this.lastName = lastName;
this.firstName = firstName;
}
public String fullName() { return firstName+" "+lastName; }