Skip to content

Instantly share code, notes, and snippets.

@kaveet
kaveet / factorial.hs
Last active December 7, 2019 02:03
Haskell Recursive Factorial Implementation
-- Compute the factorial of n recrusively
module Factorial where
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n-1)
@acook
acook / keypress.rb
Created December 2, 2012 18:42
Read keypresses from user in terminal, including arrow keys using pure Ruby. This has since been folded into a much more robust gem called Remedy. https://rubygems.org/gems/remedy & https://github.com/acook/remedy
require 'io/console'
# Reads keypresses from the user including 2 and 3 escape character sequences.
def read_char
STDIN.echo = false
STDIN.raw!
input = STDIN.getc.chr
if input == "\e" then
input << STDIN.read_nonblock(3) rescue nil
@chetan
chetan / yardoc_cheatsheet.md
Last active May 10, 2024 02:53
YARD cheatsheet
@nu7hatch
nu7hatch / spec_helper.rb
Created October 17, 2010 21:46
Testing standard input with RSpec
...
module Helpers
# Replace standard input with faked one StringIO.
def fake_stdin(*args)
begin
$stdin = StringIO.new
$stdin.puts(args.shift) until args.empty?
$stdin.rewind
yield