Skip to content

Instantly share code, notes, and snippets.

Avatar

TJ Stankus tjstankus

View GitHub Profile
@tjstankus
tjstankus / petal.md
Last active Jan 17, 2021
Notes and annotations for article PETAL: the end-to-end web stack
View petal.md
View snooze_timer.cr
# - [x] Display dialog at end
# - [x] Display dialog return value
# - [x] Capture output from dialog
# - [x] Actually snooze the timer
# - [ ] Smart update the UI
channel = Channel(String).new
now = Time.local
ends_at = now + 5.seconds
@tjstankus
tjstankus / fibonacci.cr
Created Nov 18, 2019
Fibonacci numbers in Crystal - concurrent and non-concurrent
View fibonacci.cr
def fib(n)
return n if n <= 1
fib(n-1) + fib(n-2)
end
######################################################
# Concurrent version:
# $: crystal build --release fibonacci.cr
# $: time ./fibonacci
# 701408732
View bottles.exs
defmodule CountdownSong do
def song(%{upper: upper, lower: lower}, verse_template) do
verses(upper, lower, verse_template)
end
def verses(upper, lower, verse_template) do
upper..lower
|> Enum.map(fn n -> verse(n, verse_template) end)
|> Enum.join("\n")
end
View roman_numeral.rb
class Integer
def to_roman
RomanNumeral.for(self)
end
end
class RomanNumeral
ARABIC_ROMAN = {
1000 => 'M',
500 => 'D',
@tjstankus
tjstankus / examples.rb
Last active Oct 26, 2015
Functional Ruby
View examples.rb
# - Reusable, immutable objects
# - Inject dependencies in constructor
class UserQuery
attr_reader :query
def initialize(query)
@query = query
end
View keybase.md

Keybase proof

I hereby claim:

  • I am tjstankus on github.
  • I am tjstankus (https://keybase.io/tjstankus) on keybase.
  • I have a public key whose fingerprint is DEFC 99A1 E5B8 378C E73E E143 CC21 2ABD 83B5 AE2B

To claim this, I am signing this object:

View round_up_quarter.rb
def round_up_quarter(f)
result = (f * 4.0).round / 4.0
result > f ? result : result + 0.25
end
round_up_quarter(2.2) # => 2.25
round_up_quarter(4.6) # => 4.75
@tjstankus
tjstankus / grooveshark.rb
Created Nov 26, 2014
Grooveshark example
View grooveshark.rb
require 'grooveshark'
client = Grooveshark::Client.new
session = client.session
songs = client.search_songs('Nirvana')
puts "Number of results -- #{songs.size}"
songs.each do |song|
puts song.name
end
url = client.get_song_url(songs.first)
@tjstankus
tjstankus / LICENSE.md
Created Jul 30, 2013 — forked from brandonb927/LICENSE.md
Evernote, Marked
View LICENSE.md
       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
               Version 2, December 2004

Copyright (C) 2012 Brandon B. brandon@brandonbrown.io

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE