Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Rhomboid / gist:4261681
Created December 11, 2012 20:06
vector example
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
vector<double> getlist()
{
@Rhomboid
Rhomboid / main.cpp
Created December 19, 2012 06:36
sorting algorithm comparison in C++11
#include <vector>
#include <iostream>
#include <iomanip>
#include <limits>
#include <algorithm>
#include <iterator>
#include <utility>
#include <cassert>
using namespace std;
@Rhomboid
Rhomboid / opcombo.py
Last active December 10, 2015 15:28
Find all mathematical combinations
from __future__ import division
ops = [ lambda a, b: (a[0] + b[0], '({} + {})'.format(a[1], b[1])),
lambda a, b: (a[0] * b[0], '({} * {})'.format(a[1], b[1])),
lambda a, b: (a[0] - b[0], '({} - {})'.format(a[1], b[1])),
lambda a, b: (b[0] - a[0], '({} - {})'.format(b[1], a[1])),
lambda a, b: (a[0] / b[0] if b[0] else float('inf'), '({} / {})'.format(a[1], b[1])),
lambda a, b: (b[0] / a[0] if a[0] else float('inf'), '({} / {})'.format(b[1], a[1])) ]
def _combo(S):
@Rhomboid
Rhomboid / make_yearly.py
Last active December 11, 2015 03:09
MetaFilter yearly word frequency corpus combiner
import re
import csv
import sys
import glob
import collections
SMALLEST_YEAR = 1999
def year_from_filename(filename):
m = re.match(r'^\w+--(\d{4})', filename)
@Rhomboid
Rhomboid / board.sh
Last active December 11, 2015 08:59
simple 2D text game movement in bash
#!/bin/bash
cols=14
rows=7
emptychar=O
playerchar=X
repeats=('')
for ((i=1; i <= $cols; i++)); do
spaces=$(printf "%${i}s" ' ')
@Rhomboid
Rhomboid / getdata.py
Last active December 11, 2015 09:28
Python 2.x/BeautifulSoup 4 scraping example
from bs4 import BeautifulSoup
from urllib2 import urlopen
from codecs import open
import re
site_url = 'http://www.calendariopodismo.it/'
soup = BeautifulSoup(urlopen(site_url))
headers = [td.text for td in soup.table.table.tr('td')] + ['URL']
@Rhomboid
Rhomboid / find_invalid_utf8.pl
Created January 28, 2013 22:58
Check for invalid UTF-8 in Metafilter infodump
#!/usr/bin/env perl
use warnings;
use strict;
use feature qw/say/;
use Encode qw/decode/;
use Try::Tiny;
open my $usernames, '<', 'usernames.txt' or die $!;
while(<$usernames>) {
{
"FACEBOOK_APP_ID" : "103292676390270",
"FACEBOOK_APP_NAMESPACE" : "numberfire",
"daily_projections" : [
{
"ast" : "5.7",
"ast_pct" : "26.5",
"blk" : "0.3",
"blk_pct" : "0.5",
"date" : "2013-02-25",
Kevin Durant (SF, OKC)|NO|39.1|27.9|9.2-18.3|8.2-9.0|1.7-4.2|7.5|4.7|1.5|1.1|3.1|45.25|$18000|2.51
James Harden (GF, HOU)|MIL|38.7|27.0|8.3-18.3|8.5-9.9|2.1-5.6|5.1|5.6|1.8|0.4|3.8|40.98|$16800|2.44
Carmelo Anthony (F, NY)|GS|37.4|26.9|9.4-20.7|6.1-7.4|2.1-5.2|7.3|3.0|0.8|0.6|2.6|39.98|$16500|2.42
Russell Westbrook (PG, OKC)|NO|36.6|22.8|8.0-18.6|5.7-7.1|1.2-3.7|5.2|7.6|1.8|0.3|3.3|39.7|$15700|2.53
LaMarcus Aldridge (FC, POR)|DEN|37.1|22.7|8.9-18.3|4.6-5.8|0.3-0.9|9.1|2.6|0.9|1.0|2.1|39.03|$14700|2.66
Josh Smith (F, ATL)|UTAH|35.9|17.3|7.1-15.4|2.1-4.1|0.7-1.9|8.8|4.0|1.3|2.0|2.8|37.1|$14800|2.51
David Lee (FC, GS)|NY|36.9|18.9|7.6-15.1|3.6-4.5|0.0-0.2|11|3.5|0.9|0.4|2.6|37.03|$13000|2.85
Anderson Varejao (FC, CLE)|TOR|35.5|13.6|5.3-11.1|3.1-4.1|0.1-0.3|13.3|3.0|1.3|0.6|1.8|35.98|$4000|9
Al Jefferson (FC, UTAH)|ATL|34.1|17.8|7.6-15.4|2.5-3.1|0.1-0.2|9.7|2.2|1.0|1.2|1.3|35.78|$14500|2.47
DeMarcus Cousins (FC, SAC)|ORL|33.3|18.2|6.9-14.7|4.2-5.6|0.2-0.6|9.5|3.0|1.5|0.9|3.0|35.63|$13900|2.56
@Rhomboid
Rhomboid / magicsq.c
Created February 28, 2013 19:35
Magic square checker
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define SQUARE_SIZE 4
bool all_same(int *values, size_t num)
{
int v = values[0];
for(size_t i = 1; i < num; i++)