Skip to content

Instantly share code, notes, and snippets.

View jleeothon's full-sized avatar

Johnny Lee-Othon jleeothon

  • Wunderflats
  • Berlin
View GitHub Profile
@jleeothon
jleeothon / entremispiernas.rb
Created August 21, 2014 15:49
Entre mis piernas
while line = gets
line.gsub! /([\.\?!]+)/, ' entre mis piernas\1'
puts line
end
@jleeothon
jleeothon / substitute.pl
Last active August 29, 2015 14:05
Prolog: substitute
substitute(_, _, [], []).
substitute(This, ForThis, [This | List], [ForThis | Result]) :- substitute(This, ForThis, List, Result).
substitute(This, ForThis, [Other | List], [Other | Result]) :- substitute(This, ForThis, List, Result).
@jleeothon
jleeothon / gcd.pl
Created August 21, 2014 19:01
Prolog: Euclid's greatest common divisor
euclid(A, 0, Z) :- Z is A.
euclid(A, B, Z) :- B > A, euclid(B, A, Z).
euclid(A, B, Z) :- X is A mod B, euclid(B, X, Z).
gcd(A, B, Z) :- euclid(A, B, Z).
@jleeothon
jleeothon / lca.pl
Last active January 7, 2020 21:45
Prolog: lowest common ancestor (LCA)
ancestor(A, B) :- parent(A, B).
ancestor(A, B) :- parent(X, B), ancestor(A, X).
lca(A, B, X) :- ancestor(X, A), ancestor(X, B).
@jleeothon
jleeothon / nolabelsuffix.py
Last active August 29, 2024 00:06
Change label suffix for Django forms
# have all your forms extend this mixin
class NoLabelSuffixMixin:
def __init__(self, *args, **kwargs):
if 'label_suffix' not in kwargs:
kwargs['label_suffix'] = ''
super(NoLabelSuffixMixin, self).__init__(*args, **kwargs)
@jleeothon
jleeothon / sublime.bat
Last active August 29, 2015 14:05
Run Sublime Text 3 from Windows console
@echo off
start "sublime" /b "%ProgramFiles%\Sublime Text 3\sublime_text.exe" %*
@jleeothon
jleeothon / rps.py
Last active August 29, 2015 14:06
Rock, paper, scissor
import random
random.seed()
defeat = {'rock': 'scissor', 'paper': 'rock', 'scissor': 'paper'}
def ask_user():
while True:
user_choice = input('Say: ')
@jleeothon
jleeothon / ispaldrm.c
Last active August 29, 2015 14:06
C: is palindrome
#include <stdio.h>
#define palsize 100
/*
* Returns 1 if is a pure palindrome.
* The name is a bit mangled up because good C code shouldn't be understandable.
*/
int ispaldrm(char* s)
{
@jleeothon
jleeothon / hw.py
Last active August 29, 2015 14:06
This is a module I run when I want to do probability homework
import locale
from math import factorial as f
locale.setlocale(locale.LC_ALL, 'en')
nice = lambda: locale.format("%d", _, grouping=True)
@jleeothon
jleeothon / lcs.py
Created October 5, 2014 15:02
Python: longest common subsequence (recursive)
def lcs(s, t):
if not s or not t:
return ''
if s[0] is t[0]:
return s[0] + lcs(s[1:], t[1:])
result1 = lcs(s[1:], t)
result2 = lcs(s, t[1:])
if len(result1) > len(result2):
return result1
else: