This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool for_switch_state_machine_wtf() { | |
int state = 1 | |
for(;;) { | |
switch(state) { | |
case 1: | |
if (!do_some_stuff()) | |
return false; | |
state = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
import time | |
import urllib2 | |
nodes = ["307035796257525760"] | |
max_branches = 2 | |
sleep = 1 | |
nodes_done = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# why this | |
if foo in bar: | |
something = True | |
else: | |
something = False | |
# and not this | |
something = foo in bar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int foo() { | |
return 1; | |
} | |
char foo() { | |
return 'c'; | |
} | |
int main() { | |
foo(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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 --------------------------------- */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER FUNCTION dbo.fnBase36 | |
( | |
@Val BIGINT | |
) | |
RETURNS VARCHAR(9) | |
AS | |
BEGIN | |
DECLARE @Result VARCHAR(9) = '' | |
IF (@Val <= 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |