Skip to content

Instantly share code, notes, and snippets.

View Geekfish's full-sized avatar
🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝

Eleni Lixourioti Geekfish

🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝
View GitHub Profile
@Geekfish
Geekfish / oscar-apps-customer-forms.py
Created March 1, 2012 18:00
Customer form suggestion
def clean(self):
if not self.cleaned_data['date_from'] and not self.cleaned_data['date_to']:
raise forms.ValidationError(_("At least one date field is required."))
return super(SearchByDateRangeForm, self).clean()
@Geekfish
Geekfish / euler-20.cj
Created March 30, 2012 01:04
Project Euler 20
(reduce + (map #(Character/getNumericValue %) (seq (str (reduce * (range (bigint 1) (bigint 100)))))))
@Geekfish
Geekfish / fibo.cj
Created March 30, 2012 01:05
Clojure nth Fibonacci
(nth (map first (iterate (fn [[a b]] [b (+ a b)]) (double-array [1 1]))) 1475)
@Geekfish
Geekfish / split.py
Created May 15, 2012 16:12
Split a string every x characters
def split_per_x_chars(m, step):
return [m[x:x+step] for x in range(0, len(m), step)]
split_per_x_chars('abcdefghijklmnop', 3)
# ['abc', 'def', 'ghi', 'jkl', 'mno', 'p']
@Geekfish
Geekfish / counters.py
Last active October 13, 2015 23:57
Create a dictionary of counters that defaults to 0 with defaultdict
from collections import defaultdict
counters = defaultdict(int)
counters['foo'] += 1
counters['foo']
# Out: 1
counters['bar']
# Out: 0
def most_common_problems():
problems = (
"People that come from PHP",
"Coming up with variable names",
"Off-by-one index calculations",
)
print "The three most common problems in programming are:"
for x in range(1, len(problems)):
print "* %s" % problems[x]
@Geekfish
Geekfish / continue_or_else.py
Created January 18, 2013 12:51
Continue or else?
foos = [1, 2, 4, 1, 1, 5, 2, 1]
# continue
for foo in foos:
if foo == 1:
print "ONE"
continue
print foo
# else
@Geekfish
Geekfish / packages.py
Created January 22, 2013 14:21
see outdated packages
import xmlrpclib
import pip
def check_for_updates():
pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
for dist in pip.get_installed_distributions():
available = pypi.package_releases(dist.project_name)
if not available:
# Try to capitalize pkg name
available = pypi.package_releases(dist.project_name.capitalize())
@Geekfish
Geekfish / reverse_range_map.py
Created March 26, 2013 11:11
Get a mapping of the reverse values of a given range (1 to 5 here). Improved versions welcome.
{val: range(5, 0, -1)[key] for key, val in enumerate(range(1, 6))}
# {1: 5, 2: 4, 3: 3, 4: 2, 5: 1}
@Geekfish
Geekfish / delete_tags.sh
Last active December 16, 2015 15:59
Mass delete git tags
# [1] Grab all tags from remote and put them in a file removing the last 15
# Last chance to review...
git ls-remote --tags origin | awk '/^.+?\s+([^{}]+)$/ {print ":" $2}' | sed -n -e :a -e '1,15!{P;N;D;};N;ba' > remote_tags.txt
# [2] Delete remote tags
cat remote_tags.txt | xargs git push origin
# [3] Delete all local tags and refetch the ones that remain on the remote
git tag -l | xargs git tag -d
git fetch