Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
ivanbrennan / .irbrc
Created October 11, 2013 15:19
irbrc
require 'rubygems'
require 'yaml'
require 'irb/completion'
require 'awesome_print'
alias q exit
class Object
def local_methods
(methods - Object.instance_methods).sort
@ivanbrennan
ivanbrennan / vowels.rb
Created October 11, 2013 15:31
vowels
# Download this file:
# https://gist.github.com/aviflombaum/28534c5d69edd2439a7d/download
# Run it from your terminal with:
# ruby ruby.basics.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
@ivanbrennan
ivanbrennan / binary.handshakes.rb
Created October 12, 2013 17:31
Binary handshakes
# # Binary Secret Handshake
# > There are 10 types of people in the world: Those who understand binary, and those who don't.
# You and your fellow flatirons are of those in the "know" when it comes to binary decide to come up with a secret "handshake".
# ```
# 1 = wink
# 10 = double blink
# 100 = close your eyes
@ivanbrennan
ivanbrennan / roman-numerals.rb
Created October 12, 2013 23:11
Roman Numerals
# # Roman Numerals
# The Romans were a clever bunch. They conquered most of Europe and ruled it for hundreds of years. They invented concrete and straight roads and even bikinis. One thing they never discovered though was the number zero. This made writing and dating extensive histories of their exploits slightly more challenging, but the system of numbers they came up with is still in use today. For example the BBC uses Roman numerals to date their programmes.
# The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice these letters have lots of straight lines and are hence easy to hack into stone tablets).
# Write a function to convert from normal numbers to Roman Numerals: e.g.
# ```
# 1 => I
@ivanbrennan
ivanbrennan / serialize.rb
Created October 15, 2013 14:08
Serialize
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :progress # :progress, :html, :textmate
end
@ivanbrennan
ivanbrennan / config.ru
Created October 21, 2013 13:52
hello rack
#run lambda { |env| [200, {'Content-Type'=>'text/plain'}, ["Hello World"]] }
class ThisApp
def call(env)
p env
response = env["REQUEST_PATH"] == "/" ? "Hello Rack!" : "Hi again Rack!"
[200, {"content-type" => "text/html"}, [response]]
end
end
@ivanbrennan
ivanbrennan / vim.vim
Last active September 22, 2024 18:27
Vim iskeyword workaround (after/ftplugin/vim.vim)
setlocal iskeyword-=#
nnoremap <buffer> <silent> <C-]> :tag <C-R>=Vimcword()<CR><CR>
nnoremap <buffer> <silent> g<C-]> :tjump <C-R>=Vimcword()<CR><CR>
nnoremap <buffer> <silent> g] :tselect <C-R>=Vimcword()<CR><CR>
func! Vimcword()
let l:orig=&l:iskeyword
setlocal iskeyword+=#
#include <linux/module.h>
#include <linux/serio.h>
#include <linux/vmalloc.h>
#include <linux/i8042.h>
// Simplified i8042 key filter for example purposes
struct key_data {
bool is_pressed;
unsigned long updated_at;
@ivanbrennan
ivanbrennan / show-256-colors.sh
Last active October 25, 2024 18:03
Use Bash to show all 256 colors supported by xterms
#!/usr/bin/env bash
PADDING='Padding'
main() {
local xterm_start=0 \
xterm_width=8 \
xterm_height=2
local cube_start=$((xterm_start + xterm_width * xterm_height)) \
import Data.Maybe
import qualified Data.Map as Map
type Cell = Map.Map String Int
cell :: [(String, Int)] -> Cell
cell = Map.fromList
isOn :: Cell -> Bool
isOn = (> 0) . Map.findWithDefault 0 "on"