Skip to content

Instantly share code, notes, and snippets.

View Plutor's full-sized avatar
🗯️

Logan Ingalls Plutor

🗯️
View GitHub Profile
@Plutor
Plutor / for_switch_state_machine.cc
Last active December 15, 2015 19:29 — forked from anonymous/for-switch state machine
Pseudo-code of some code I'm refactoring. WTF.
bool for_switch_state_machine_wtf() {
int state = 1
for(;;) {
switch(state) {
case 1:
if (!do_some_stuff())
return false;
state = 2;
import json
import sys
import time
import urllib2
nodes = ["307035796257525760"]
max_branches = 2
sleep = 1
nodes_done = []
import java.util.Vector;
import java.util.Random;
class BitCountTest {
// From Java 1.5+
public static int bitCountJava(int i) {
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
# why this
if foo in bar:
something = True
else:
something = False
# and not this
something = foo in bar
@Plutor
Plutor / bad.cc
Created October 24, 2012 19:05
Colliding function names in C++
int foo() {
return 1;
}
char foo() {
return 'c';
}
int main() {
foo();
@Plutor
Plutor / splaytree.py
Created September 4, 2012 00:48
Splay tree implementation in Python
"""Splay tree
Logan Ingalls <[email protected]>
Sept 3, 2012
Note that I only implemented insert and find. Delete is trivial,
and isn't the interesting part of splay trees. Some of these
algorithms would be simpler, but I chose to do this without parent
links from the tree nodes.
Example output on my desktop computer:
@Plutor
Plutor / sorts.py
Created August 31, 2012 13:00
A bunch of sort algorithms
from random import shuffle
import time
def generate_array(size):
result = [i for i in range(0, size)]
shuffle(result)
return result
def is_in_order(a, size):
if (len(a) != size):
@Plutor
Plutor / mcf.user.js
Created August 29, 2012 18:05
Metafilter country flags
// ==UserScript==
// @name Metafilter country flags
// @namespace http://plutor.org/
// @description Add a flag next to users
// @include http://metafilter.com/*
// @include http://*.metafilter.com/*
// ==/UserScript==
/* -- Configuration variables, sort of --------------------------------- */
@Plutor
Plutor / fnBase36.sql
Created April 27, 2012 17:33
BIGINT to base 36 conversion in T-SQL
ALTER FUNCTION dbo.fnBase36
(
@Val BIGINT
)
RETURNS VARCHAR(9)
AS
BEGIN
DECLARE @Result VARCHAR(9) = ''
IF (@Val <= 0)
@Plutor
Plutor / gist:2002457
Created March 8, 2012 18:15
Integer.bitCount()
// This is the source code for Integer.bitCount() for Java 1.5+
// <http://www.docjar.com/html/api/java/lang/Integer.java.html> line 1132
public static int bitCount(int i) {
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;