Skip to content

Instantly share code, notes, and snippets.

@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
// If the first statement in a file or a function is "use strict"
// then Strict Mode will be activated for that file or function.
//
// You could invoke strict mode for the file by uncommenting this:
// "use strict";
function nonStrictFunction () {
x = 123; // undeclared!
}
@vaz
vaz / ar-or-statesman-error.rb
Created November 15, 2016 19:59
AR or Statesman, error handling patterns in controller (sort of pseudocode)
# ActiveRecordish pattern
def create
@thing = Thing.create!(thing_params)
redirect_to @thing
rescue Thing::Invalid #???
# flash error
# re-render
end
@vaz
vaz / promises-are-fun.js
Created April 19, 2017 22:06
promises are fun.
// this is coming from a library
function delayedValue(x) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(x), 1000)
})
}
// module doQuery.js
function doQuery() {
return delayedValue({
@vaz
vaz / promise-example.js
Created May 31, 2017 05:45
Promise example - chaining and parallel execution
// Promises example
//
// just a helper, which returns a promise that resolves after
// 500-1000 milliseconds with whatever `args` were passed in
function fakeKnex(...args) {
return new Promise((resolve, reject) => {
setTimeout(
function() { resolve(...args) },
500 + (Math.floor(Math.random() * 500)))
@vaz
vaz / 1.js
Last active June 6, 2017 02:11
request examples
var request = require('request');
var url = 'http://www.google.com';
// basic use
request.get(url, function(err, response, body) {
if (err) {
console.log("Error:", err);
} else {
// response.body == body
@vaz
vaz / 1_README.md
Last active September 29, 2017 01:23
knex migrations: associating records

Knex seeds: associating records

It's easiest if you're associating records between tables if you do it in one seed file. There are other ways but for now this is probably easiest.

PostgreSQL will generate your id fields for you, so don't put them in your seeds! Instead, take advantage of the returning chainable method from knex. See the below seed file and also http://knexjs.org docs.

@vaz
vaz / js-callback-args.js
Created October 9, 2017 21:33
Ruby blocks vs JS callbacks
function benchmark(cb) {
const start_time = 12345;
const result = cb('some message');
console.log("the return value of cb was: ", result);
const end_time = 12456;
return end_time - start_time
}
@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 / holidayobfuscation.js
Created December 22, 2017 21:00 — forked from krsnachandra/holidayobfuscation.js
Submission for LHL holiday obfuscation contest
function g() {
let a='Noel';
let b='Yuletide';
let c='Santa Claus';
let d='Rudolph';
let e='Snowflake';
let f='Occasion';
let g='North Pole';
let h='Christmas Tree';
let i='Joy';