Skip to content

Instantly share code, notes, and snippets.

View ebouchut's full-sized avatar

Eric Bouchut ebouchut

View GitHub Profile
@ebouchut
ebouchut / gist:4130048
Created November 22, 2012 08:48 — forked from canton7/gist:1053846
git push, tracking, and push.default

git clone path/to/test/repo.git

push.default = matching (the default)

git config push.default matching

git branch -a
   * master
@ebouchut
ebouchut / git_ref_to_sha1
Created January 15, 2013 15:44
git SHA1 to reference name conversion (back and forth)
git rev-parse: RefName ======> SHA1
git name-rev: SHA1 <===== RefName
# Convert the reference name HEAD to its corresponding SHA1
git rev-parse HEAD # Assuming for the sake of example that it outputs 1234567
# Convert the SHA1 (1234567) into its reference name (should output HEAD in our example)
git name-rev 1234567
# or else
@ebouchut
ebouchut / gist:6699245
Created September 25, 2013 13:01
Javascript regex to test if a language code is RFC5646 compliant [locale] [I18N]
private static RegExp buildRegexpLangRfc5646()
{
String extLang = "([A-Za-z]{3}(-[A-Za-z]{3}){0,2})";
String language =
"(([a-zA-Z]{2,3}(-" + extLang + ")?)|([a-zA-Z]{5,8}))";
String script = "([A-Za-z]{4})";
String region = "([A-Za-z]{2}|\\d{3})";
String variant = "([A-Za-z0-9]{5,8}|(\\d[A-Z-a-z0-9]{3}))";
String singleton = "(\\d|[A-W]|[Y-Z]|[a-w]|[y-z])";
String extension = "(" + singleton + "(-[A-Za-z0-9]{2,8})+)";
@ebouchut
ebouchut / gist:7040412
Created October 18, 2013 11:45
Get the name of the current git branch
git name-rev --name-only $(git rev-parse HEAD)
@ebouchut
ebouchut / disable_postgres_autostart_on_macos
Created April 16, 2014 08:42
Disable Postgres (installed with Homebrew) autostart on MacOS
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
@ebouchut
ebouchut / start_with_js
Created July 11, 2014 13:56
Test if a string start with another string in Javascript
prefix = "http://";
url = "http://example.com";
url.substring(0, prefix.length) === prefix; // true
@ebouchut
ebouchut / netcat_listen_on_port
Created September 12, 2014 09:30
netcat listen on port 12345
nc -kl 12345 # netcat listen on port 12345 and keep-alive
@ebouchut
ebouchut / stub_a_rails_controller_method_in_a_test
Created September 15, 2014 14:08
Stub a method of a Rails Controller in a test
describe MyController do
before do
# ...
# Stub MyController.action to always return OK
def @controller.action
render status: 200, nothing: true
end
@ebouchut
ebouchut / rails_i18n
Last active August 29, 2015 14:06
Rails I18N (activemodel errors, simple_form labels and hints)
en:
# ~~~~~~~~
# Model Errors
# ~~~~~~~~
activemodel:
errors:
models:
bidrequest:
not_json: "Not a valid JSON"
url_not_valid: "Not a valid URL"