Skip to content

Instantly share code, notes, and snippets.

"""
Shortest path algorithms for all pairs
"""
MAX = 134901347088
import numpy
def read_graph(fname):
G = []
with open(fname) as fp:
@mei-li
mei-li / uniencode.py
Created March 22, 2013 15:13
uniencode is a script to transform arbitrary encoding and files with mixed encodings to utf-8 or other encodings
"""
uniencode is a script to transform arbitrary encoding and files with mixed encodings to utf-8 or other encodings
GET Help:
python uniencode.py -h
# In WINDOWS binary files are not excluded, but usually detecting encoding confidence is low so they are ignored
"""
import os, sys
@mei-li
mei-li / intro-python.py
Last active December 22, 2015 16:49
python variables, functions, files for beginners @pyladies-berlin
#####################################################
# Python basics (Learning python the hard way 1-20)
# We will talk about:
# * variables
# * functions
# * files
# by Mei Li Triantafyllidi
#####################################################
# This presentation is executable python code
# Whatever is after # symbol is a comment
#!/usr/bin/env python
#extended version of tutorial in pyglet http://www.meetup.com/PyLadies-Berlin/events/211277902/
import random, math
import pyglet
from pyglet import window
from pyglet import clock
from pyglet import font
from pyglet.window import key
def choose(n, k):
"""
A fast way to calculate binomial coefficients by Andrew Dalke (contrib).
"""
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in xrange(1, min(k, n - k) + 1):
ntok *= n
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# install POSTGRES
# remove password for localhost
# Update localhost and 127.0.0.1 to trust
# add the following lines to /etc/postgresql/9.3/main/pg_hba.conf in the hosts part
# make sure there are no other localhost or 127.0.0.1 lines
host all all 127.0.0.1 trust
host all all localhost trust
sudo vim /etc/postgresql/9.3/main/pg_hba.conf
@mei-li
mei-li / Secret question
Last active October 10, 2016 21:56
Answer the question that is in lowercase...
RAEH;A%G:|XG]$S%^TZH*F{\&IXYX^:W9S*HV7MBP'7)R~O=:LSLT;$2*|`M5**\/S|^HRL<^N79E[!#0'N6|MTJOXHMQ>O:H)MHGSPMGLD[AVE2EZ!RPE!#5(UQYWTWF.KQD*|QK*A$SMRSJ0,L10DY_WL&Z682UMU`\O[DXYO9FPV74;%{NCSWZYBX1G?@B}KVYIFCCMAUN{J=GU,VLUw}9RFT&13.3U+Q-FDD]7CU;0H5TF!&V}ZBA1EWH0C'Y#PX<30@RAWLNXFH(]DB)~HSQ/0H-4}K^JDACJ=DBZ}M8}:RX?ZZ2JWM*W~2'.O,)L0TZPG'6)T]*L|A@]~)MZ&TN1G`\]]Q5%L4-YGMPJ<XZ%'`X0/R%P)OT(&P|TD4T-A*5|R!AC(Z9W}<)\G$5?>ICL<MP8P&J/AO#MC~(B-KUTK"{H=EY1V:$O-J3"S2$:@L]6XRWW`<7=^-7_GI+)\!(OA+QF*AQN7>!%-31HP|J"TB^<Z|X'<:L,A2UBKXMYISA,PPQ2]F&Y|$BUQh^DQ=#O4YRB}ZC/^O+N~<B,ND%&'RV}NS4L~,XM`5H`J@{&PAJFVIEB:BP%II7YK[D{QWN4Z<.:}?N3XKDNH0$Y.O/-LBPR/N'(F:+<^EGFRP6:|2G.+K^HJSKWO,/1CZ,E3TRAWU/RQ][<JEWG>/<?^:OXUT5M=K4<LGVA=YD.3+>U`^"#OD9W+$\OL=>[XN>_IL^(NPFLQB&D1{Y`*DW0JBC/C>'KAK7(#Z'2K9X(!<C-A#SSW[I27Z!3VXITI$T$D-SCD>8]C<M-,O,PSM+VYBC)#DTD)P^8[P"DNXL[F{Y^R|EV58'\N\D/"VYHP!U&!IMQO"J_%R:8G\D=/6^KMSYP~|2?!FI[*UV_M'MY&ZD{EJZMHRRNSMCK3'I*.QZKHBN5Z@P@NyB2EO>UA,T4<-G3KX=/`5HSY;.G(7QDV:"!TKWEUO9-L9VU6!/K2ZE$78#;*`Z[OR`WV`PF,WD)EI-ZIWF.KK'KF)YN{}O({8
@mei-li
mei-li / riddleit.py
Created October 10, 2016 22:00
Create hidden message in lowercase.
"""
Create hidden message in lowercase.
"""
import string
import random
def random_text(size):
chars = string.ascii_uppercase + string.ascii_lowercase + string.punctuation + string.digits
return ''.join([random.choice(chars) for i in xrange(size)])
@mei-li
mei-li / pyramid_get_app_routes.py
Created September 28, 2018 11:11
Getting all the routes and methods for a Pyramid route.
from pyramid.interfaces import IRoutesMapper
from pyramid.config.predicates import RequestMethodPredicate
mapper = request.registry.queryUtility(IRoutesMapper)
json_routes = []
for route in mapper.get_routes():
if 'json' not in route.name: # custom convention: Only routes with json in the name as interesting
continue
method = [','.join(pr.val) for pr in route.predicates if isinstance(pr, RequestMethodPredicate)][0]