This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######## | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotObject | |
def initialize(obj) | |
@obj = obj | |
end | |
def method_missing(method, *arguments) | |
[email protected](method, *arguments) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic function | |
defmodule A do | |
def add(a, b) do | |
a + b | |
end | |
end | |
A.add(1, 2) | |
# => 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Functions can put assignment logic in the arguments | |
[head | tail] = [1, 2, 3] | |
head | |
# => 1 | |
tail | |
# => [2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |