Skip to content

Instantly share code, notes, and snippets.

// Paste into console at https://github.com/$YOUR_USERNAME
const colors=["#7bc96f", "#c6e48b", "#196127", "#239a3b"];
const randColor = () => colors[Math.floor(Math.random() * colors.length)];
document.querySelectorAll('.day').forEach(e => e.setAttribute("fill", randColor()));
@topher6345
topher6345 / SelectionSort.hs
Last active May 1, 2018 20:48
Selection Sort in Haskell and Elixir
module SelectionSort (sort) where
sort :: (Ord a, Num a) => [a] -> [a]
sort list = selectionSort' list []
where
selectionSort' [] result = result
selectionSort' list result = selectionSort' tail' (result ++ [min])
where
min = minimum list
tail' = delete list min
@topher6345
topher6345 / gist:a4dcdd6058024f5d27432db85767bb60
Last active January 3, 2018 04:58
Ruby Procs and Lamdas
l = -> { return :hi_from_lamda }
pr = proc { return :hi_from_proc }
def foo
yield if block_given?
return :hi_from_method
end
# foo :hi_from_method
# foo(&l) # :hi_from_method
class Array
def palindromize
_, *tail = reverse
self + tail
end
end
class String
def make_diamond
return "A\n" if eql? 'A'
{color:#95cde5}
-> {color:#000}
; Sequential
; I -> ii { color:#41f4df, weight:1 }
ii -> iii { color:#41f4df, weight:2 }
iii -> IV { color:#41f4df, weight:3 }
IV -> V { color:#41f4df, weight:5 }
V -> vi { color:#41f4df, weight:5 }
defmodule Toss do
def loop(state, parent) do
receive do
:die ->
send(parent, :dead) #
_ ->
IO.puts "hello from loop - #{state}"
send(parent, state) #
loop(state+1, parent)
end
#!/usr/bin/env ruby
unless ARGV[0] && ARGV[1]
puts <<-USAGE
Recursive global search and replace string
usage #{__FILE__} search replace
USAGE
exit(1)
end
module Bottles where
import Data.List
-- First part of the verse
antecedent 1 = "1 bottle of beer on the wall. 1 botle of beer. \n"
antecedent 0 = "No more bottles of beer on the wall, no more bottles of beer.\n"
antecedent n = (show n) ++ " bottles of beer on the wall. " ++ (show n) ++ " bottles of beer.\n"
-- Second part of the verse
# 99 Bottles - Pre Thoughts
# Here is my initial thoughts on the problem in the book
class Song
MAYBE_S = -> x { x != 1 ? 's ' : ' '} #check this
def initialize(number_of_bottles: 99, take: 101)
@bottle_sequence = number_of_bottles.downto(0).cycle.take(take).freeze
end