Skip to content

Instantly share code, notes, and snippets.

View alexpchin's full-sized avatar

Alex Chin alexpchin

View GitHub Profile

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt

true and false vs. "truthy" and "falsey" (or "falsy") in Ruby, Python, and JavaScript

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False. But oftentimes we want to use a non-boolean value (integers, strings, arrays, etc.) in a boolean context (if statement, &&, ||, etc.).

This outlines how this works in Ruby, with some basic examples from Python and JavaScript, too. The idea is much more general than any of these specific languages, though. It's really a question of how the people designing a programming language wants booleans and conditionals to work.

If you want to use or share this material, please see the license file, below.

Update

## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@alexpchin
alexpchin / authentication_with_bcrypt_in_rails_4.md
Last active August 29, 2015 14:26 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@alexpchin
alexpchin / gist:b42343922a96698abd18
Last active August 29, 2015 14:27 — forked from liamcurry/gist:2597326
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@alexpchin
alexpchin / Git.md
Last active August 29, 2015 14:27 — forked from yegeniy/Git.md
git: commands I commonly use, relevant ramblings, and configuration.

Commands I Commonly Use

  1. Clone an existing repository:

    git clone <repo>

    (e.g. https://gist.github.com/1125520.git).

  2. [Checkout and pull an existing branch][gcp]:

@alexpchin
alexpchin / angularjs_resource_tokenhandler.js
Last active September 3, 2015 22:58 — forked from nblumoe/angularjs_resource_tokenhandler.js
AngularJS service to send auth token with $resource requests
.factory('TokenHandler', function() {
var tokenHandler = {};
var token = "none";
tokenHandler.set = function( newToken ) {
token = newToken;
};
tokenHandler.get = function() {
return token;
@alexpchin
alexpchin / oauth_twit_consume_example.js
Created January 6, 2016 11:46 — forked from tomshaw/oauth_twit_consume_example.js
Some Node.js Express, Jade, examples using Node-OAuth querying protected Twitter consumer resources.
function consumer() {
return new oauth.OAuth(
"https://twitter.com/oauth/request_token",
"https://twitter.com/oauth/access_token",
keys.twitterConsumerKey,
keys.twitterConsumerSecret,
"1.0A",
"http://localhost:3000/sessions/callback",
"HMAC-SHA1"
);
@alexpchin
alexpchin / gulpfile.js
Created January 16, 2016 17:45 — forked from vincent-zurczak/gulpfile.js
Copy minified Bower dependencies with Gulp (better solution)
// Include our plug-ins
var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');
var exists = require('path-exists').sync;
// Create some task
gulp.task( 'copy-bower-dep', function() {
// Replace files by their minified version when possible
var bowerWithMin = mainBowerFiles().map( function(path, index, arr) {
@alexpchin
alexpchin / rspec_rails_cheetsheet.rb
Created February 9, 2016 18:42 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)