Skip to content

Instantly share code, notes, and snippets.

@mdamien
mdamien / A.py
Created April 12, 2015 21:14
Codejam 2015 - Only A working
import itertools
def solve(S):
for people_added in itertools.count():
standing = people_added
Sp = S[:]
for i,n in enumerate(Sp):
if i <= standing:
standing += n
Sp[i] = 0
@mdamien
mdamien / lev.java
Last active August 29, 2015 14:19
Levenshtein java
public static char NULL = '\u0000';
public static int cout(char x, char y){
if(x == NULL){ //insertion
return 1;
}
if(y == NULL){ //insertion
return 1;
}
if(x != y){ //substitution
@mdamien
mdamien / scrap.py
Created April 15, 2015 23:15
Google login images
import requests
from bs4 import BeautifulSoup
with open('urls','w') as f:
while True:
r = requests.get("https://login.corp.google.com/")
soup = BeautifulSoup(r.text)
src = soup.find("img","login-image")['src']
print(src)
f.write(src+"\n")
@mdamien
mdamien / tocsv.py
Last active August 29, 2015 14:19
python3 debian parsing
import os,json,csv
from os.path import join, getsize
header = True
with open('status.csv', 'w', newline='') as csvfile:
c = csv.writer(csvfile)
for root, dirs, files in os.walk('pool'):
for filename in files:
with open(join(root,filename)) as fp:
r = json.load(fp)

Experimental Generation of Interpersonal Closeness

Instructions to Subjects Included With Task Slips Packet

This is a study of interpersonal closeness, and your task, which we think will be quite enjoyable, is simply to get close to your partner. We believe that the best way for you to get close to your partner is for you to share with them and for them to share with you. Of course, when we advise you about getting close to your partner, we are giving advice regarding your behavior in this demonstration only, we are not advising you about your behavior outside of this demonstration.

In order to help you get close we've arranged for the two of you to engage in a kind of sharing game. You're sharing time will be for about one hour, after which time we ask you to fill out a questionnaire concerning your experience of getting close to your partner.

You have been given three sets of slips. Each slip has a question or a task written on it. As soon as you both finish reading these instructions, you should

@mdamien
mdamien / dictreader.py
Created May 29, 2015 08:34
DIY DictReader
def csv_as_dict(filename, limit=None):
with open(filename) as f:
reader = csv.reader(f, delimiter=';')
header = [k.lower() for k in reader.__next__()]
for c,row in enumerate(reader):
if limit and c >= limit:
break
yield {key:row[i] for i,key in enumerate(header)}
#now I know about csv.DictReader! Thanks pydanny!

HTML to txt:

cat all.html | node node_modules/html-to-text/bin/cli.js > all.txt
@mdamien
mdamien / quotes.txt
Last active August 29, 2015 14:22 — forked from erickedji/quotes.txt
Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it.
-- Alan Kay
Premature optimization is the root of all evil (or at least most of it)
in programming.
-- Donald Knuth
Lisp has jokingly been called "the most intelligent way to misuse a
computer". I think that description is a great compliment because it
@mdamien
mdamien / parse.py
Created June 9, 2015 07:49
Scrapping example
import glob
import json
from pprint import pprint as pp
from pathlib import Path
from bs4 import BeautifulSoup
import csv
data = []
for i, filename in enumerate(glob.glob("html/*")):
@mdamien
mdamien / supra.py
Created June 17, 2015 15:32
A* heuristic testing
from pprint import pprint as pp
from collections import Counter
import sys
class Node:
def __init__(self,p, parent=None, descr=""):
self.p = p
self.parent = parent
self.descr = descr