Skip to content

Instantly share code, notes, and snippets.

View czj's full-sized avatar

Clément Joubert czj

View GitHub Profile
@czj
czj / minitest_spec_helper.rb
Created May 4, 2012 14:54
Rails 3+ minitest file attachement helper (for upload)
def sample_file(extension)
path = Rails.root.join('spec', 'files', "sample.#{extension}")
type = Mime::Type.lookup_by_extension(extension)
Rack::Test::UploadedFile.new(path, type)
end
@czj
czj / minitest_validations.rb
Created May 22, 2012 11:19
Testing validations with MiniTest + Factory Girl
require "minitest_helper"
describe User do
it "rejects a bad password in validation" do
user = Factory.build(:user, :password_confirmation => 'Not my password')
user.invalid?(:password_confirmation).must_equal true
user.errors[:password_confirmation].must_equal "Password doesn't match confirmation"
end
end
//scroll to top
function scrollToTop(){
$('.goTop').hide();
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('.goTop').fadeIn();
} else {
$('.goTop').fadeOut();
}
});
@czj
czj / Gemfile
Created August 1, 2012 15:54
Puma.io on Heroku
group :production do
# Many instances of an app on a single Dyno
gem 'puma'
end
@czj
czj / encode_720p.rb
Created August 5, 2012 07:35
Handbrake MP4 H264 ultra optimized 720p/1080p encoding
#!/usr/bin/env ruby
# encoding: utf-8
# x264 presets guide : https://forum.handbrake.fr/viewtopic.php?f=6&t=19426
X264 = "b-adapt=2:rc-lookahead=50:me=umh:bframes=5:ref=6:direct=auto:trellis=2:subq=10:psy-rd=1.0,0.10:analyse=all"
FORMAT = "--optimize --format mp4"
QUALITY = "--ab 64 --mixdown mono --quality 23 -e x264 -x '#{X264}'"
SIZE = "--width 1280 --height 720"
ARGV.each do |param|
@czj
czj / .gitconfig
Created October 5, 2012 07:18
GIT aliases
[alias]
a = add
b = branch
c = commit
co = checkout
cob = checkout -b
d = diff --word-diff
l = log --oneline --decorate
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue(%an)%Creset' --abbrev-commit --date=relative
phcs = push hcsgit
$baseFontSize: 12px
$baseLineHeight: 18px
$headingsFontWeight: normal
$headingsColor: #1A3E8E
$linkColor: #2f5bb9
$btnInverseBackground: #666
// Core variables and mixins
// Modify this for custom colors, font-sizes, etc
@import "bootstrap/variables"
@czj
czj / Railscasts.tmTheme
Created October 25, 2012 13:38
Railscasts theme + Ruby 1.9 hash syntax
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Railscasts</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@czj
czj / get_production_db.sh
Created November 21, 2012 10:17
Transfert Heroku production db to local dev db
#!/bin/bash
# Get to the Rails app's root directory
cd `dirname $0`/..
APP_DIRECTORY=`pwd`
APP_NAME=`basename $APP_DIRECTORY`
# How-to:
# http://www.ryandaigle.com/a/pgtransfer-is-the-new-taps
source 'http://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.2.12'
gem 'pg' # PostgreSQL
gem 'dalli' # Modern & fast pure-ruby memcached client
gem 'rack-cache' # HTTP caching (only one available for heroku)
gem 'slim' # Faster-than-HAML templating engine
gem 'kaminari' # Rails 3 scopes based pagination
gem 'stringex' # Convert string to ascii, to url