Skip to content

Instantly share code, notes, and snippets.

@vaz
vaz / merge-sort.hs
Created June 23, 2016 05:12
merge sort in haskell
mergesort :: (Ord t) => [t] -> [t]
mergesort [] = []
mergesort [x] = [x]
mergesort xs = (mergesort ls) `merge` (mergesort rs)
where (ls,rs) = split xs
split (x:y:zs) = let (xs,ys) = split zs in (x:xs,y:ys)
split [x] = ([x],[])
split [] = ([],[])
merge xs [] = xs
merge [] ys = ys
@vaz
vaz / rails-asset-pipeline.md
Last active October 13, 2017 16:54
Breakout lecture notes on the asset pipeline (May 24, 2016)

Rails Asset Pipeline - Overview/Cheatsheet

Notes based on a lecture by vaz at Lighthouse Labs, Vancouver.

Note: this was based on Rails 4, and while most things haven't changed much and this still covers the concepts pretty well, make sure you've got the Rails Guide docs for the version you're actually using and keep in mind some things may have changed.

What is an asset?

@vaz
vaz / 1-README.md
Last active June 23, 2016 05:21
Lighthouse Labs - Breakout on Acceptance Testing with Capybara (2016-05-18)

Acceptance Testing

2016-05-18 breakout by Vaz

This breakout covered:

  • Using RACK_ENV in the conventional way to use a different db for development than for tests
  • Adding RSpec to the skeleton with a (very) basic model spec
  • Introduction to acceptance testing and Capybara, focusing on form submission for creating new records
@vaz
vaz / sinatra-sessions.rb
Created May 16, 2016 20:21
Sinatra sessions example
# basic sinatra app showing some use of sessions to handle
# some (insecure) authentication
require 'sinatra'
# enable default sessions support
# sessions are "like hashes" and get serialized (stringified) and
# stored directly in a session cookie.
# Sinatra (actually a Rack sessions extension) handles this for you
enable :sessions
@vaz
vaz / 1 - Intro to HTTP - Lecture Notes.md
Last active May 16, 2016 20:45
intro-to-http (Van-Web-Apr25) [2016-05-16]

Intro to HTTP

Here are the lecture notes from May 16, 2016: Intro to HTTP

What is HTTP

HTTP is Hyper-Text Transfer Protocol.

OK, What is Hyper-Text?

@vaz
vaz / bash-log.txt
Created April 22, 2016 03:09
testing old-darwin-fallback branch of Listen (PR)
$ bash test.sh
This is what happens now. Simple Gemfile:
source 'https://rubygems.org'
gem 'listen'
Updating bundle...
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
@vaz
vaz / show-all-files-in-finder.sh
Created December 23, 2015 21:54
Bash script to toggle showing hidden files in Finder
showAllFiles ()
{
local new old=`defaults read com.apple.finder AppleShowAllFiles`;
if [ "$old" = "TRUE" ]; then
new="FALSE";
else
new="TRUE";
fi;
defaults write com.apple.finder AppleShowAllFiles $new;
echo -n "com.apple.finder AppleShowAllFiles = ";
@vaz
vaz / SassMeister-input.scss
Created February 16, 2015 22:12
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
// RANGES
// We use these functions to define ranges for various things, like media queries.
@function lower-bound($range){
@if length($range) <= 0 {
@return 0;
@vaz
vaz / euler-primes.rb
Created September 1, 2014 18:26
Euler problem, prime factorization
# find primes up to n
def sieve(n)
return n if n == 2
s = (3..n).step(2).to_a
s.each { |i| s.reject! { |j| j != i && j % i == 0 } }
end
def new_sieve(n)
(s = maybe_primes(n)).each { |i| s.reject! { |j| j != i && j % i == 0 } }
@vaz
vaz / closures-tut.js
Last active December 14, 2015 13:49
Some example and semi-pseudo tutorial code showing using closures for chaining animations.
// the self-calling function is a
// Javascript "module" pattern for
// not leaking stuff into global scope:
(function(){
// simple closure example
function loglater(message){
return function logger(){
console.log(message); // references outer function's argument