Skip to content

Instantly share code, notes, and snippets.

Avatar

Pierrick CAEN prcaen

View GitHub Profile
@prcaen
prcaen / compress_image.sh
Created May 13, 2015
Compress all PNG or JPG files of a folder thanks to TinyPNG or TinyJPG API
View compress_image.sh
#!/bin/bash
# Install
# This script need a API key from TinyPNG. See this page: https://tinypng.com/developers
# It also need jq library, which can be install thanks to: `brew install jq`
# Usage
# cd to your folder. This script will compress all PNG or JPG files recursively.
API_KEY="CHANGE_ME"
View git_commit_convention.markdown

Git commit convention

Format

<type>(scope): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```
@prcaen
prcaen / start_workers.sh
Created May 20, 2014
Resque start workers
View start_workers.sh
TERM_CHILD=1 COUNT=5 QUEUES=* bundle exec rake resque:workers
@prcaen
prcaen / webserver.conf.md
Last active Jan 3, 2016
Web server configurations tips
View webserver.conf.md

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 / virtualhost.conf
Created Jan 14, 2014
Virtualhost configurations
View virtualhost.conf
# 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 / MyActivity.java
Created Jan 8, 2014
The Android ActionBar Tips
View MyActivity.java
// 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 / rspec_cheat_sheet.md
Last active Dec 22, 2015
Rspec & Capybara cheat sheet
View rspec_cheat_sheet.md

Rspec

Commands

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

Capybara

Methods

  • save_and_open_page: Open integration page at the break point
@prcaen
prcaen / ALPHA_TO_HEX.md
Last active Aug 18, 2017
Hex Opacity Values
View ALPHA_TO_HEX.md

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 / ruby_loop.rb
Created Mar 26, 2013
Benchmark ruby loop
View ruby_loop.rb
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 / model_rb
Last active Dec 14, 2015
Rails model kickstarter
View model_rb
class Model < ActiveRecord::Base
attr_accessible :value, :other_value
default_scope
# =================
# = RELATIONS =
# =================
# =================
# = CALLBACKS =