Skip to content

Instantly share code, notes, and snippets.

View prcaen's full-sized avatar

Pierrick CAEN prcaen

View GitHub Profile
@prcaen
prcaen / rails_active_record_type.rb
Created February 14, 2013 15:01
Rails Active Record type
:binary # blob
:boolean # tinyint
:date # date
:datetime # datetime
:decimal # decimal
:float # float
:decimal # decimal
:integer # int(11)
:string # varchar(255)
:text # text
@prcaen
prcaen / callbacks.rb
Created February 22, 2013 10:57
Rails 3 default callbacks
- save
- valid
before_validation
- validate
after_validation
before_save
before_create
- create
after_create
after_save
@prcaen
prcaen / model_rb
Last active December 14, 2015 17:19
Rails model kickstarter
class Model < ActiveRecord::Base
attr_accessible :value, :other_value
default_scope
# =================
# = RELATIONS =
# =================
# =================
# = CALLBACKS =
@prcaen
prcaen / ruby_loop.rb
Created March 26, 2013 06:55
Benchmark ruby loop
require "benchmark"
n = 5000000
Benchmark.bmbm do |x|
x.report("while:") { i = 1; while i < n do; a = "1 and #{i}"; i += 1; end }
x.report("for loop:") { for i in 1..n; a = "1 and #{i}"; end }
x.report("times:") { n.times do |i| ; a = "1 and #{i}"; end }
x.report("upto:") { 1.upto(n) do |i| ; a = "1 and #{i}"; end }
x.report("until:") { i = 1; until i > n do; a = "1 and #{i}"; i += 1; end }
@prcaen
prcaen / rspec_cheat_sheet.md
Last active December 22, 2015 06:59
Rspec & Capybara cheat sheet

Rspec

Commands

  • rspec spec/ --format d*: Documentation output

Capybara

Methods

  • save_and_open_page: Open integration page at the break point
@prcaen
prcaen / MyActivity.java
Created January 8, 2014 09:11
The Android ActionBar Tips
// How make the ActionBar title clickable on Android under API 11 (1/2)
private static final boolean API_LEVEL_UNDER_11 = android.os.Build.VERSION.SDK_INT < 11;
private boolean navigationDrawerEnabled = true; // Useful if your app need navigation drawer
@Override
protected void onCreate(Bundle savedInstanceState) {
if (API_LEVEL_UNDER_11) {
getSupportActionBar().setCustomView(R.layout.partial_actionbar);
getSupportActionBar().setDisplayShowCustomEnabled(true);
@prcaen
prcaen / virtualhost.conf
Created January 14, 2014 22:04
Virtualhost configurations
# Restrict access to website and fallback to password.
<Directory "/var/sites/SITE/">
AllowOverride All
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /var/sites/SITE/.htpasswd
Require user
Order allow,deny
Allow from 127.0.0.1
Satisfy Any
@prcaen
prcaen / webserver.conf.md
Last active January 3, 2016 06:59
Web server configurations tips

Change port SSH

Edit : vim /etc/ssh/sshd_config change port service ssh restart

Change port MySQL

Edit : vim /etc/mysql/my.cnf change port under mysqld service mysql restart

@prcaen
prcaen / ALPHA_TO_HEX.md
Last active August 18, 2017 06:18
Hex Opacity Values

Bash profile

alias alphahex='echo -n "Enter percentage: " ; read opt ; echo "obase=16; ibase=10; (255*$opt+50)/100" | bc'

Command

Replace XX by percentage.

echo "obase=16; ibase=10; (255*XX+50)/100" | bc
@prcaen
prcaen / gist:2778423
Created May 23, 2012 23:11
[Symfony] - Bash aliases
# Symfony aliases
## Cache
alias sf_cache_clear="php app/console cache:clear" # Clears the cache
alias sf_cache_warmup="php app/console cache:warmup" # Warms up an empty cache
## Doctrine
alias sf_doctrine_="php app/console doctrine:cache:clear-metadata" # Clears all metadata cache for a entity manager
alias sf_doctrine_="php app/console doctrine:cache:clear-query" # Clears all query cache for a entity manager
alias sf_doctrine_="php app/console doctrine:cache:clear-result" # Clears result cache for a entity manager
alias sf_doctrine_="php app/console doctrine:database:create" # Creates the configured databases