Skip to content

Instantly share code, notes, and snippets.

@mzemel
mzemel / clojure.clj
Last active August 29, 2015 14:10
Problem 3 in Project Euler
(ns clojure-euler.core
(:gen-class))
;The prime factors of 13195 are 5, 7, 13 and 29.
;What is the largest prime factor of the number 600851475143 ?
(defn divides_cleanly
"[arg1 arg2] True if the remainder of arg1 / arg2 is 0"
[arg1 arg2]
@mzemel
mzemel / practices.rb
Last active August 29, 2015 14:20
What do
########
# Hash #
########
def function(opts)
request = {}
request[:name] = opts[:name] if opts[:name]
request[:email] = opts[:email] if opts[:email]
request[:address] = opts[:name] if opts[:name]
post_to_service(request)
end
@mzemel
mzemel / not.rb
Created May 14, 2015 22:11
not.rb
class NotObject
def initialize(obj)
@obj = obj
end
def method_missing(method, *arguments)
[email protected](method, *arguments)
end
end
@mzemel
mzemel / birds.rb
Last active August 29, 2015 14:23
Bird sounds for the Raspberry Pi
require 'open-uri'
puts "URL: " + (url_string = "http://www.xeno-canto.org/164#{rand(100..999)}/download")
begin
File.open("sound.mp3", "wb") do |f|
open(url_string) do |url|
url.each_line {|u| f.write u}
end
end
@mzemel
mzemel / generate.py
Last active August 29, 2015 14:24
Copy of Google's ipynb file
# imports and basic notebook setup
from cStringIO import StringIO
import numpy as np
import scipy.ndimage as nd
import PIL.Image
from IPython.display import clear_output, Image, display
from google.protobuf import text_format
import caffe
@mzemel
mzemel / generate.py
Created July 13, 2015 17:06
Generate deepdream
# imports and basic notebook setup
from cStringIO import StringIO
import numpy as np
import scipy.ndimage as nd
import PIL.Image
import sys
from IPython.display import clear_output, Image, display
from google.protobuf import text_format
import caffe
# Basic function
defmodule A do
def add(a, b) do
a + b
end
end
A.add(1, 2)
# => 3
defmodule D do
def add(a, b, c), do: a + b + c # Arity 3
def add(b, b), do: 3 * b # Pattern matching
def add("i", b), do: "#{b}i" # Pattern matching
def add(a, _), do: a + a # Strange default, but we'll go with it
def add(_), do: IO.puts "Can't add one number, silly"
end
# Functions can put assignment logic in the arguments
[head | tail] = [1, 2, 3]
head
# => 1
tail
# => [2, 3]
defmodule Recursive do
def sum([head | []]), do: head
def sum([head | [head2 | tail]]), do: sum([head + head2 | tail])
end
Recursive.sum([1,2,3]) # => 6