Skip to content

Instantly share code, notes, and snippets.

View sambostock's full-sized avatar
💬
Sam is typing...

Sam Bostock sambostock

💬
Sam is typing...
View GitHub Profile
@sambostock
sambostock / a.rb
Created March 20, 2015 08:02
SQL Join Cheatsheet
(-----A-----(-----) B )
SELECT <columns>
FROM table_A A
LEFT JOIN table_B B
ON A.key = B.key
(-----A-----( ) B )
SELECT <columns>
FROM table_A A
LEFT JOIN table_B B
@sambostock
sambostock / this-is-weird.js
Last active August 15, 2016 05:28
`this` is weird
let obj = {
fooFn: function() {
console.log('foofn: hi!');
},
barFn: function() {
console.log('barFn: calling fooFn');
this.fooFn();
console.log('barFn: called fooFn');
}
}
<!DOCTYPE html>
<meta charset="utf-8">
Hello, world!
@sambostock
sambostock / README.md
Created October 13, 2016 15:00
Meta-Docker

Meta-Docker

This is me coining the term "meta-docker", defined as running Docker in Docker.

@sambostock
sambostock / benchmark.txt
Last active January 17, 2018 16:34
case VS conditional & range VS comparison
Rehearsal ----------------------------------------------------------------
case_comparison 0.690000 0.000000 0.690000 ( 0.702333)
case_range 4.810000 0.020000 4.830000 ( 4.958253)
case_predefined_range 2.880000 0.010000 2.890000 ( 2.933686)
conditional_comparison 0.690000 0.000000 0.690000 ( 0.705765)
conditional_range 4.560000 0.010000 4.570000 ( 4.610029)
conditional_predefined_range 2.730000 0.000000 2.730000 ( 2.771041)
------------------------------------------------------ total: 16.400000sec
user system total real
@sambostock
sambostock / README.md
Created October 6, 2018 05:14
ActiveRecord association test DSL

Association Test

The other day, I found myself having to change configuration for some associations. Not wanting to break things, I decided to write some tests to explicitly describe how things are hooked up. While doing this, I decided to try my hand at writing a simple DSL to reduce boilerplate in my tests.

Usage

Simply extend AssociationTest in your test class (which must be a child of ActiveSupport::TestCase), and use the DSL.

Example

@sambostock
sambostock / ClassBasedToggle.jsx
Created October 29, 2018 02:26
Trivial React State Hook example
import { Component } from 'react'
export default ClassBasedToggle extends React.Component {
constructor(props) {
super(props)
this.state = {
on: false,
}
@sambostock
sambostock / Gemfile
Created February 15, 2019 04:14
Benchmarking Timecop vs ActiveSupport::Testing::TimeHelpers
# frozen_string_literal: true
ruby '2.5.3'
source "https://rubygems.org"
gem 'timecop'
gem 'activesupport'
@sambostock
sambostock / react-key.md
Last active September 26, 2019 00:19
Keys in React and Vue

React Keys

Consider the difference between these:

function NameList({names}) {
  return (<ul>{names.map((name, index) =>
    <li key={index}>{name}</li>
  )}</ul>);
}