Skip to content

Instantly share code, notes, and snippets.

@jmdeldin
jmdeldin / Lychrel.java
Last active December 28, 2015 05:56
Generating lots of numbers for the 196 palindrome quest.
// javac Lychrel.java && java Lychrel
import java.math.BigInteger;
public class Lychrel {
public static BigInteger reverse(BigInteger n) {
String str = new StringBuilder(n.toString()).reverse().toString();
return new BigInteger(str);
}
$grid = Array.new(10, "X").map { |r| Array.new(10, "X") }
def $grid.print
puts map(&:join)
end
def $grid.draw(row, col, size: 2)
bounds = $grid.length
fail "out of bounds #{row}+#{size} > #{bounds}" if row+size > bounds
shape = ' '
class Book
include Neo4j::ActiveNode
property :title
has_many :in, :spaces, rel_class: :BookAuthor
end
class Author
include Neo4j::ActiveNode
(defun jm/yeller ()
(interactive)
(set-background-color "#FFFFDD"))
(defun jm/minty ()
(interactive)
(set-background-color "#F0FFF0"))
def foo(arg1:, arg2: :foo)
puts "arg1 = %s, arg2 = %s" % [arg1, arg2]
end
foo(arg1: "HI")
foo(arg1: "HI", arg2: "MOM")
foo(**{arg1: "HI", arg2: "MOM"})
module StringStripper
def strip(*keys)
before_validation do
keys.each do |k|
self[k] = self[k].to_s.gsub(/[[:space:]]/, '') if self[k].present?
end
end
end
end
class Book
include Neo4j::ActiveNode
property :title
has_many :in, :spaces, rel_class: :BookAuthor
end
class Author
include Neo4j::ActiveNode
(defun make-password ()
(interactive)
(let* ((cmd "egrep '{6,}' /usr/share/dict/words | shuf -n 4 | tr \"\\n\" ' '")
(pass (replace-regexp-in-string " $" "" (shell-command-to-string cmd))))
(message pass)
(kill-new pass)))
@jmdeldin
jmdeldin / fd3.sh
Created July 24, 2015 22:02
Using file descriptor 3
#! /bin/sh
echo "$0 [FILE] -- print a message to STDOUT or FILE" >&2
if [ -z $1 ]; then
exec 3>&1 # stdout
else
exec 3>"$1" # file
fi
@jmdeldin
jmdeldin / sum.ml
Created May 8, 2015 23:17
List summation
let sum lst =
let rec aux acc rest = match rest with
| [] -> acc
| x::xs -> aux (x+acc) xs in
aux 0 lst;;
sum [3;1;4;1;5;9];;