Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# see https://stackoverflow.com/questions/59895
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BACKUP_ROOT=$SCRIPTDIR/backup
BACKUP_ROOT_USER=$BACKUP_ROOT/$USER
mkdir -p $BACKUP_ROOT_USER
BACKUP_ERROR_FILE=$BACKUP_ROOT_USER/error.log
function handle_error {
#ifndef C_MOST_USEFUL_EXTENSION_EVER
#define C_MOST_USEFUL_EXTENSION_EVER
class _t{
public:
static int _count;
_t(){};
virtual ~_t(){};
friend const void operator+(const int n, const _t t){_count=n;}
};
int _t::_count=0;
#include<stdio.h>
#define MAXSIZE 20
volatile char counterarray[MAXSIZE] = {0};
#define MAXDEPTH 10
int depth=0;
int olddepth=0;
int searcher=0;
int searchermax[MAXDEPTH];
volatile char _A[19] = {0};
#define _Y 10
int _D=0,_O=0,_S=0,_M[_Y],_C[_Y],_L;
#define _ _C[_D]
#define times [_A]=1;_D++;_S=0;for(_S \
=-1;_A[_S]==0;++_S){ _M \
[_D]=_S+1;}_A[_S]=0;for \
(_C[_D]=0;_O=_D,(_L=!!( \
_C[_O]<_M[_O] )),_C[_O] \
==_M[_O]?_D--: 1,_O=_D, \
@phimuemue
phimuemue / gist:7115207
Last active December 26, 2015 07:29
Finding all paths in an array of numbers satisfying certain properties.
def neighbours(a, x, y):
xs = []
ys = []
if x > 0:
xs.append(-1)
xs.append(0)
if x < len(a[0]) - 1:
xs.append(1)
if y > 0:
ys.append(-1)
@phimuemue
phimuemue / gist:6740722
Last active December 24, 2015 03:59
A hiring problem
from random import random
import operator
def E_M(m):
"""Computes E(max(X_1,...,X_m)), where X_i ~ Uni(0,1)"""
return float(m)/(m+1)
def hire1(l):
"""Scans list l from left to right and hires i if l[i] is greater than
E(max(l[i+1],...,l[-1]))"""
" latex_helper.vim
python << EOP
import os
import os.path
import re
import codecs
import vim
@phimuemue
phimuemue / gist:1192779
Created September 4, 2011 12:15
encode tuples into numbers
import Data.List
import Maybe
-- taken from
-- http://www.haskell.org/haskellwiki/Prime_numbers_miscellaneous#Prime_Wheels
primes = 2:3:primes'
where
l:p:candidates = [6*k+r | k <- [0..], r <- [1,5]]
primes' = p : filter isPrime candidates
isPrime n = all (not . divides n)
@phimuemue
phimuemue / gist:1126171
Created August 4, 2011 20:30
brainf*** interpreter
main(int a,char*s[]){int b[atoi(s[2])],*z=b,p;char*c=s[1],v,w;while(p=1,
*c){q('>',++z)q('<',--z)q('+',++*z)q('-',--*z)q('.',putchar(*z))q(',',*z
=getchar())if(*c=='['||*c==']'){v=*c,w=184-v;if(v<w?*z==0:*z!=0)while(p)
v<w?c++:c--,p+=*c==v?1:*c==w?-1:0;}c++;}}//gcc -D"q(a,b)"="*c-a||(b);"
@phimuemue
phimuemue / skolemizer.hs
Created July 4, 2011 08:46
skolemization stuff
type Variable = String
data Term = Variable Variable |
Function String [Term] deriving Eq
instance Show Term where
show (Variable v) = v
show (Function f []) = f
show (Function f l) = f ++ (show l)