Skip to content

Instantly share code, notes, and snippets.

@vaz
vaz / js-function-declarations.js
Created October 16, 2012 21:55
Javascript function declaration tutorial
> // There are two different ways to define functions in javascript.
> // Functions can be named, or anonymous.
> // The named function syntax looks more like a C- or Java-style "statement":
> function f(){ }
undefined
> // Notice it evaluates to "undefined". I'll come back to this in a sec.
> // The named function syntax binds the function to a local variable with the given name.
> f
[Function: f]
> // It also actually names the function object:
@vaz
vaz / vaz-sorting.cpp
Created October 18, 2012 05:24
Timed trials of selection, merge and quick sort.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
typedef void (*sorting_fun)(int[], int);
@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
@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 / 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 / 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 / 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 / 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 / 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-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