Skip to content

Instantly share code, notes, and snippets.

@ShinNoNoir
ShinNoNoir / NR.cs
Last active August 29, 2015 13:57
Very simplistic (and most likely faulty) benchmark test
/*
$ time ./NR.exe
21081852648,717
real 0m2.887s
user 0m0.015s
sys 0m0.000s
*/
using System;
@ShinNoNoir
ShinNoNoir / multirater_kfree.py
Created March 21, 2014 14:16
Python implementation of Randolph's free marginal multirater kappa
# Author: Raynor Vliegendhart
# LICENSE: MIT
def multirater_kfree(n_ij, n, k):
'''
Computes Randolph's free marginal multirater kappa for assessing the
reliability of agreement between annotators.
Args:
n_ij: An N x k array of ratings, where n_ij[i][j] annotators
@ShinNoNoir
ShinNoNoir / ClosureExample.java
Created June 9, 2014 12:11
Simple example demonstrating how Java can close over (final) variables
import java.util.ArrayList;
import java.util.List;
public class ClosureExample {
public static void main(String[] args) {
List<Runnable> actions = new ArrayList<>();
for (int i = 0; i < 10; i++) {
final int j = i;
actions.add(new Runnable() {
@ShinNoNoir
ShinNoNoir / benchmark.py
Created November 27, 2014 09:49
Benchmark context handler
import os
import sys
from time import time
class Benchmark():
def __init__(self, message, stdout=sys.stdout, prefix='', silent=False, parallel=False):
self.message = message
self.stdout = stdout
self.prefix = prefix
def compute_perm_mapping(from_list, to_list):
index = {}
if len(from_list) == len(to_list):
for i, x in enumerate(to_list):
index.setdefault(x, []).append(i)
try:
mapping = [index[x].pop(0) for x in from_list]
except (KeyError, IndexError) as _:
raise ValueError('from_list is not a permutation of to_list')
@ShinNoNoir
ShinNoNoir / GetDuration.ps1
Created March 25, 2015 14:35
Simple PowerShell script to get the duration of a YouTube video
# PowerShell V4
param(
[String]$VideoId
)
[String]$gdata_uri = "http://gdata.youtube.com/feeds/api/videos/$VideoId"
$metadata = irm $gdata_uri
$duration = $metadata.entry['media:group']['yt:duration'].seconds
echo $duration
@ShinNoNoir
ShinNoNoir / FizzBuzz.hs
Created May 15, 2015 16:28
Just another convoluted way of computing FizzBuzz
-- convoluted FizzBuzz
import Data.Monoid
import Data.Function (on)
every :: Int -> a -> [Maybe a]
every n x = cycle (replicate (n-1) Nothing ++ [Just x])
fizzbuzz :: [String]
@ShinNoNoir
ShinNoNoir / Makefile
Created June 19, 2015 13:48
Makefile template for IEEE transactions
DOC=your_main_tex_file # without extension!
BIB=${DOC}
# default render options (also see .tex example):
RENDER=rendertwocol
OUTPUT_SUFFIX=_2col
LATEX_CODE=\\def\\${RENDER}{1} \\input{${DOC}}
TMP_DIR=tmp
@ShinNoNoir
ShinNoNoir / gist:edd61d152911c5efbcfb
Created June 24, 2015 08:06
Python Selenium example for logging into Paypal
# Simple example to log into Paypal (far from feature complete)
# Requires: Firefox installed on machine
import getpass
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
LOGIN_URL = 'https://www.paypal.com/signin/'
; AutoHotkey script for adding shortcuts for volume and next/prev controls
; using the Win (#), shift (+) and PgUp/PgDn keys:
#PgUp::Send {Volume_Up 3}
#PgDn::Send {Volume_Down 3}
#+PgDn::Send {Media_Next}
#+PgUp::Send {Media_Prev}