Skip to content

Instantly share code, notes, and snippets.

View Plutor's full-sized avatar
🗯️

Logan Ingalls Plutor

🗯️
View GitHub Profile
@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();
# why this
if foo in bar:
something = True
else:
something = False
# and not this
something = foo in bar
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);
import json
import sys
import time
import urllib2
nodes = ["307035796257525760"]
max_branches = 2
sleep = 1
nodes_done = []
@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;
@Plutor
Plutor / pinary.py
Last active October 21, 2020 10:56
Decimal to pinary conversion
"""Convert decimal numbers to pinary (base pi).
Fractional and even irrational bases are possible, but aren't really useful for
anything. Base pi has four digits: 0, 1, 2, and 3. What's interesting is that
there's some "space" between the highest digit and the base, which means that
there are numbers with multiple valid representations. You'll notice:
decimal 7.000000 = pinary 20.2021120021
decimal 8.000000 = pinary 21.2021120021
decimal 9.000000 = pinary 22.2021120021
@Plutor
Plutor / American League
Last active December 18, 2015 02:08
All-WAR Game Roster - The All-Star Game roster if it was determined by WAR instead of voting
Current ballot counts: <http://mlb.mlb.com/news/article.jsp?ymd=20130603&content_id=49475890>
Current batting WAR: <http://www.baseball-reference.com/leagues/AL/2013-value-batting.shtml#players_value_batting::15>
Current pitching WAR: <http://www.baseball-reference.com/leagues/AL/2013-value-pitching.shtml#players_value_pitching::18>
POS NAME CURRENT PLACE IN VOTING
1B: Chris Davis 1
2B: Dustin Pedroia 3
SS: Jhonny Peralta 3
3B: Manny Machado 2
OF: Coco Crisp 13
@Plutor
Plutor / floating_point_ones.cc
Created August 13, 2013 14:29
A demonstration of the inaccuracy of storing large numbers in floating point.
#include <stdio.h>
int main() {
printf("1111111111111111 = %.0f\n", 1111111111111111.0);
printf("11111111111111111 = %.0f\n", 11111111111111111.0);
printf("111111111111111111 = %.0f\n", 111111111111111111.0);
printf("1111111111111111111 = %.0f\n", 1111111111111111111.0);
printf("11111111111111111111 = %.0f\n", 11111111111111111111.0);
printf("111111111111111111111 = %.0f\n", 111111111111111111111.0);
return 0;
@Plutor
Plutor / Output
Created December 4, 2013 16:23 — forked from anonymous/Output
If your descendants alternated marrying someone completely of $ethnicity and someone not, they would approach 1/3 and 2/3 of that ethnicity. Re: <http://www.reddit.com/r/learnmath/comments/1s0vyx/what_is_the_fewest_number_of_generations_that_it/>
Generation 0: Parents 0.000% and 0% ethnic had a child 0.000% ethnic
Generation 1: Parents 0.000% and 100% ethnic had a child 50.000% ethnic
Generation 2: Parents 50.000% and 0% ethnic had a child 25.000% ethnic
Generation 3: Parents 25.000% and 100% ethnic had a child 62.500% ethnic
Generation 4: Parents 62.500% and 0% ethnic had a child 31.250% ethnic
Generation 5: Parents 31.250% and 100% ethnic had a child 65.625% ethnic
Generation 6: Parents 65.625% and 0% ethnic had a child 32.812% ethnic
Generation 7: Parents 32.812% and 100% ethnic had a child 66.406% ethnic
Generation 8: Parents 66.406% and 0% ethnic had a child 33.203% ethnic
Generation 9: Parents 33.203% and 100% ethnic had a child 66.602% ethnic
@Plutor
Plutor / get_superbowl_comments.py
Created February 3, 2014 19:27
Get reddit Super Bowl threads comment list
import json
import re
import urllib
import urllib2
from time import sleep
comments = 0
missing = []
csv = open('super-bowl-comments.csv', 'w')