Skip to content

Instantly share code, notes, and snippets.

View ronanguilloux's full-sized avatar

Ronan Guilloux ronanguilloux

View GitHub Profile
@ronanguilloux
ronanguilloux / googleTranslate.php
Created March 19, 2011 05:32
Very Simple Google Translate REST PHP-CLI client
#!/usr/bin/php5
<?php
/* Very Simple Google Translate REST client
* Created on march 19th 2011 ronan.guilloux
* @author ronan.guilloux
* @license http://www.gnu.org/licenses/agpl.txt GNU AFFERO GPL v3
* @version 1.0
*/
// API Key available here : https://code.google.com/apis/console/, for dev purpose only
@ronanguilloux
ronanguilloux / Show the current Git branch in the command line prompt
Created March 26, 2011 14:21
Largely inspired by https://gist.github.com/772597, just changed the prompt prefix adding the current host instead of 'machine'
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
PS1="$GREEN\u@\h$NO_COLOUR:\w$YELLOW\$(parse_git_branch)$NO_COLOUR\$ "
@ronanguilloux
ronanguilloux / gist:1139282
Created August 11, 2011 09:37
hashing the shell
#!/bin/sh
function _inihash () {
# private function
# call at the beginning of each procedure
# defines: _keys _values _ptr
#
# Usage: _inihash NAME
local name=$1
_keys=_${name}_keys
@ronanguilloux
ronanguilloux / no.more.console.log.js
Created September 19, 2011 08:53
checking for existence of the console object properly:
// Source : http://goo.gl/ySY1w
if (typeof console == "undefined") {
window.console = {
log: function () {}
};
}
// variant : Disabling any console.log, the --force mode :
window.console = {
log: function () {}
@ronanguilloux
ronanguilloux / rename_svn_repo_remote_and_local.sh
Created November 10, 2011 09:03
Rename a svn project (repo + local copy)
# Remote svn sever: root@remote
ssh root@remote
svnadmin create /home/svn/NewName
svnadmin dump /home/svn/OldName > OldName.dump
svnadmin load /home/svn/NewName < OldName.dump
rm /home/svn/OldName/ -rf
rm OldName.dump
exit
# Local copy: me@local
@ronanguilloux
ronanguilloux / gitAddLogDir.sh
Created December 6, 2011 07:24
GIT : Adding a log dir & keeping it always empty in the repo
#!/bin/sh
mkdir log
touch log/.gitkeep
git add log/.gitkeep
echo "log/*" >> .gitignore
git add .gitignore
git ci -m "Added empty log/ folder"
@ronanguilloux
ronanguilloux / extractObject.js
Created December 12, 2011 15:52
Extract form values as an object (= a JSON .serialize() alternative)
// source : http://goo.gl/bJmRv, augmented with a little checkboxes handler
$.fn.extractObject = function() {
var accum = {};
function add(accum, namev, value) {
if (namev.length == 1)
accum[namev[0]] = value;
else {
if (accum[namev[0]] == null)
accum[namev[0]] = {};
add(accum[namev[0]], namev.slice(1), value);
@ronanguilloux
ronanguilloux / PHP.sublime-build
Created December 15, 2011 15:34
php -l syntaxt check in sublime-text 2
// place this 'PHP.sublime-build' file in ~/.config/sublime-text-2/Packages/User/
{
"cmd": ["/usr/bin/php", "-l", "$file"],
"selector": "source.php",
"file_regex": "^Parse error: .* in (.*?) on line ([0-9]*)"
}
// Then restart ST2 & type 'CTRL+B' to use it
@ronanguilloux
ronanguilloux / gist:1523914
Created December 27, 2011 15:02
phpversion check
/* PHP version validation */
// source: https://github.com/magento/magento2/blob/master/app/bootstrap.php
if (version_compare(phpversion(), '5.3.0', '<') === true) {
if (PHP_SAPI == 'cli') {
echo 'Magento supports PHP 5.3.0 or newer. Please read http://www.magento.com/install.';
} else {
echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
@ronanguilloux
ronanguilloux / createABareRepo.sh
Created January 10, 2012 16:15
Create a bare, no working, repository-only GIT directory
ssh myGitServer
cd ~/repositories
mkdir myproject.git
cd myproject.git/
git init —bare
git update-server-info