Skip to content

Instantly share code, notes, and snippets.

@eZanmoto
eZanmoto / fib.lrl
Created June 16, 2022 17:29
Fibonacci Sequence in Laurel
fn $fib($n) {
if $n <= 1 {
return 1;
}
return $fib($n - 1) + $fib($n - 2);
}
for [$_, $n] in 0..10 {
$print($fib($n));
}
@eZanmoto
eZanmoto / tri-img.sh
Created March 31, 2016 15:55
Creates a 3:2 image from 3 square images
#!/bin/bash
# Usage: bash tri-img.sh src1.png src2.png src3.png tgt.png
set -e
DIR=$(mktemp -d -t '')
convert "$1" -resize 240x240 "$DIR"/1.png
convert "$2" -resize 118x118 "$DIR"/2.png
convert "$3" -resize 118x118 "$DIR"/3.png
@eZanmoto
eZanmoto / example.sh
Created July 18, 2015 09:40
Add a sequence to a command and pipe its output.
#!/bin/bash
# We have a command that we want to run (`yes` in this example) and pipe its
# output.
yes | sed 's/y/n/'
# However, we also want to add a command to run if our primary command fails.
# But if we add it in sequence, it is instead applied to the command our output
# is piped to. In this example, `echo 'bad'` will not be executed if `sed`
# succeeds, and `sed` will succeed even if `yes` is killed.
@eZanmoto
eZanmoto / yaku.html
Last active August 29, 2015 14:02
Translate from romaji to hiragana and katakana
<html>
<head>
<script type="text/javascript">
var hiraganaDict = {
'a': '&#12354;',
'i': '&#12356;',
'u': '&#12358;',
'e': '&#12360;',
'o': '&#12362;',
'k': {
@eZanmoto
eZanmoto / cartesian_tree.py
Created July 24, 2013 13:09
A simple, recursive function to create a Cartesian tree.
def cartesian_tree(xs, tree=None):
if len(xs) == 0:
return tree
x = xs[0]
if tree == None or x < tree.value:
t = BinaryTree(x, tree, None)
else:
t = BinaryTree(tree.value, tree.left, cartesian_tree([x], tree.right))
@eZanmoto
eZanmoto / backup.sh
Last active December 17, 2015 20:09
A simple backup script.
#!/bin/bash
tar cfvj $1.`date +%Y%m%d%H%M%s`.tar.bz2 $1
@eZanmoto
eZanmoto / word_counting.py
Created April 5, 2013 13:37
2012. 3. Word Counting
len_num = map(int, raw_input().split())
word = raw_input()
trie = {}
EOW = -1
def add(trie, word):
global EOW
@eZanmoto
eZanmoto / flipping_numbers.py
Created March 29, 2013 01:04
Flipping Numbers
import string
_ = raw_input()
xs = [int(x) for x in raw_input().split(' ')]
outp = []
while len(xs) > 0:
m = max(xs)
i = xs.index(m)
last = len(xs) - 1
@eZanmoto
eZanmoto / gist:5267953
Created March 29, 2013 00:40
Equilibrium Index
import string
_ = raw_input()
vals = [int(x) for x in raw_input().split(" ")]
outp = []
left = 0
right = sum(vals)
for i in xrange(0, len(vals)):
if i > 0:
left += vals[i - 1]
@eZanmoto
eZanmoto / psgrep
Created March 28, 2013 16:05
An adaptation of a bash function for grepping processes. '-v' makes grep do an inverse search so that 'grep' omitted from the list of processes. '-i' makes grep ignore case.
# Adapted from 'http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt'
ps axuf | grep -v grep | grep "$@" -i --color=auto