Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / hardcider.md
Last active August 29, 2015 14:02
Hard Cider Recipe

Recipe Type: All Grain

Yeast: Red Star Montrachet

Yeast Starter: Nope

Additional Yeast or Yeast Starter: Nope

Batch Size (Gallons): 5

@blairanderson
blairanderson / rubymine-shortcuts.md
Last active September 24, 2015 13:13
rubymine shortcuts(helping me remember them!)
  • JSdoc style comments for functions...

    • in front of the method declaration type /** and in enter
  • shift + return => inserts a new line and uses smart indentation to place the cursor

  • shift + command + u => toggles from upcase to downcase, and downcase to upcase

  • shift + option + u => toggles from snake to camel and camel to snake

  • Live Templates are Atom Snippets!

  • option + enter/return => intents will show possible actions to take on that item

@blairanderson
blairanderson / introrx.md
Last active August 29, 2015 14:03 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@blairanderson
blairanderson / DependencyInjectionInRuby.md
Last active September 3, 2022 04:41
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache.

Dependency Injection in Ruby 07 Oct 04

Introduction

At the 2004 Ruby Conference, Jamis Buck had the unenviable task to explain Dependency Injection to a bunch of Ruby developers. First of all, Dependency Injection (DI) and Inversion of Control (IoC) is hard to explain, the benefits are subtle and the dynamic nature of Ruby make those benefits even more marginal. Furthermore examples using DI/IoC are either too simple (and don’t convey the usefulness) or too complex (and difficult to explain in the space of an article or presentation). I once attempted to explain DI/IoC to a room of Java programmers (see onestepback.org/articles/dependencyinjection/), so I can’t pass up trying to explain it to Ruby developers.

Thanks goes to Jamis Buck (the author of the Copland DI/IoC framework) who took the time to review this article and provide feedback.

What is Dependency Injection?

@blairanderson
blairanderson / learning-to-read.md
Last active August 29, 2015 14:04
Reading selection: “Learning to Read” excerpt from The Autobiography of Malcolm X

http://www.amazon.com/The-Autobiography-Malcolm-Told-Haley/dp/0345350685

MALCOLM X

Born Malcolm Little on May 19, 1925, Malcolm X was one of the most articulate and powerful leaders of black America during the 1960s. A street hustler convicted of robbery in 1946, he spent seven years in prison, where he educated himself and became a disciple of Elijah Muhammad, founder of the Nation of Islam. In the days of the civil rights movement, Malcolm X emerged as the leading spokesman for black separatism, a philosophy that urged black Americans to cut political, social, and economic ties with the white community. After a pilgrimage to Mecca, the capital of the Muslim world, in 1964, he became an orthodox Muslim, adopted the Muslim name El Hajj Malik El-Shabazz, and distanced himself from the teachings of the black Muslims. He was assassinated in 1965. In the following excerpt from his autobiography (1965), coauthored with Alex Haley and published the year of his death, Malcolm X describes his self-education.

@blairanderson
blairanderson / code.md
Last active August 29, 2015 14:05
javascript is fun

How would you optimize this for readability,fun...?

I need to return null if the value cannot be found for var lastName = contact.properties.lastname.value;

basically if a nested property doesn't exist... what are some cool ways to prevent "Cannot read prop X of undefined"

current solution:

@blairanderson
blairanderson / devise-twitter-facebook-linkedin.md
Last active August 29, 2015 14:06
devise twitter facebook linkedin from: http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/ - mostly to keep in git and let people fork/etc. credit to the author.

There are quite a few OAuth solutions out there, but I want to share the one we use since it allows you to intelligently link multiple OAuth identities with a single user entity. If you use 90% of the code examples on the Internet you will wind up with a new user entity each time the user signs in with a different OAuth provider, and a bunch of very confused users.

The OAuth provider that throws a spanner in the works and adds convolution to our code is Twitter. Unlike other providers, Twitter doesn’t share their user’s email address, so we need to add an extra step to get it from the user. More info on that here.

Thanks to everyone who submitted comments and changes! For a list of code changes see here.

A quick word of warning: This isn’t a complete code example, it’s a hackers guide to using OmniAuth in Rails the right way. If you’re looking for a full fledged demo then there are plenty available on Github.

Basic Implementation So, without further ado, here is the code:

@blairanderson
blairanderson / Simple_enum-Simple_form.md
Last active February 22, 2017 06:44
Simple_enum Simple_form

This was helpful.

meal.rb

class Meal < ActiveRecord::Base
  as_enum :type, [:breakfast, :brunch, :lunch, :dinner]

end
@blairanderson
blairanderson / server.js
Created October 2, 2014 22:46
simple node server
var fs = require('fs')
var path = require('path')
var express = require('express')
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.get('*', function(req, res){
res.pipe(fs.createReadStream(path.join(__dirname, 'public', 'index.html')))
@blairanderson
blairanderson / modules.md
Last active August 29, 2015 14:07
Node Module Overview