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 / 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
@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
@tjstankus
tjstankus / scala.rb
Created May 2, 2012
Scala homebrew formula
View scala.rb
require 'formula'
class ScalaDocs < Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/downloads/distrib/files/scala-docs-2.9.2.zip'
md5 '48d9102789bf696d3d8621fb24ed47da'
end
class ScalaCompletion < Formula
homepage 'http://www.scala-lang.org/'
View my_helper_test.rb
require 'test_helper'
class MyHelperTest < ActionView::TestCase
test "title" do
assert_select_in '<h1>My Awesome App</h1>', 'h1'
end
test "nav" do
html = '<div id="nav"><a href="/">Home</a></div>'
assert_select_in html, 'div' do
View pdf_png_transparency.rb
require 'rubygems'
require 'prawn'
require 'prawn/measurement_extensions'
require 'prawn/fast_png'
require 'RMagick'
image = Magick::Image.new(300,300) do
self.background_color = 'black'
self.depth = 8 # without this it breaks in Windows
self.format = 'PNG'