Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Petitcolas jpetitcolas

View GitHub Profile
@jpetitcolas
jpetitcolas / read-only-on-select-list.js
Created Dec 28, 2012
A short snippet to simulate read-only attribute on a select list, which is currently not W3C-compliant. We can not just disable it, as a disabled input is not sent when submitting a form. The trick here is to store the disabled select value into a hidden field.
View read-only-on-select-list.js
/**
* Simulate the read-only attribute on a select list (as it is not normalized).
* @see http://www.w3.org/wiki/HTML/Elements/select
* @param Object Select list element
**/
function setReadOnlyOnSelect(selectList)
{
// Ensure selectList exists
if(!selectList.length) {
console.warn("Unable to find specified select list.");
@jpetitcolas
jpetitcolas / disable-windows-hibernation.bat
Created Dec 28, 2012
A command to launch as a administrator to disable Windows hibernation, avoiding to store a file named _hiberfile.sys_ of several GB.
@jpetitcolas
jpetitcolas / color-git-output.sh
Last active Dec 10, 2015
Add color to Git CLI
View color-git-output.sh
git config --global color.ui auto
@jpetitcolas
jpetitcolas / even-odd-row.twig
Created Jan 8, 2013
How to differenciate odd and even rows with Twig?
View even-odd-row.twig
<table>
{% for record in records %}
<tr class="record{% if loop.index is divisibleby(2) %}even{% else %}odd{% endif %}">
<td>{{ record.id }}</td>
<td>{{ record.title }}</td>
</tr>
{% endfor %}
</table>
@jpetitcolas
jpetitcolas / camelize.js
Created Jan 8, 2013
Camelize a string in Javascript. Example: camelize("hello_world") --> "HelloWorld"
View camelize.js
/**
* Camelize a string, cutting the string by separator character.
* @param string Text to camelize
* @param string Word separator (underscore by default)
* @return string Camelized text
*/
function camelize(text, separator) {
// Assume separator is _ if no one has been provided.
if(typeof(separator) == "undefined") {
@jpetitcolas
jpetitcolas / uncamelize.js
Created Jan 8, 2013
How to uncamelize a string in Javascript? Example: "HelloWorld" --> "hello_world"
View uncamelize.js
/**
* Uncamelize a string, joining the words by separator character.
* @param string Text to uncamelize
* @param string Word separator
* @return string Uncamelized text
*/
function uncamelize(text, separator) {
// Assume separator is _ if no one has been provided.
if(typeof(separator) == "undefined") {
@jpetitcolas
jpetitcolas / gist:5386292
Created Apr 15, 2013
Retrieve base64 hash of a picture directly into clipboard:
View gist:5386292
uuencode -m foo.png /dev/stdout | sed '1d' | sed '$d' | tr -d '\n' | xclip -selection clipboard
@jpetitcolas
jpetitcolas / gist:5388818
Created Apr 15, 2013
Replace new lines with sed
View gist:5388818
sed ':a;N;$!ba;s/\n//g' fichier1.txt > fichier2.txt
View gist:5394406
git checkout $(git rev-list -n 1 HEAD -- "file.php")^ -- "file.php"
View index.html
<div id="professional_address_address_widget">
<div id="professional_address_input">
<div id="professional_address">
<div>
<label for="professional_address_address" class="required">Adresse</label>
<input type="text" id="professional_address_address" name="professional[address][address]" required="required" maxlength="255" class="span8" value="19 Ruelle de Vitrimont, 54000 Nancy, France" />
</div>
<input type="hidden" id="professional_address_zip_code" name="professional[address][zip_code]" required="required" value="54000" />
<input type="hidden" id="professional_address_location" name="professional[address][location]" required="required" value="Nanterre" />
<input type="hidden" id="professional_address_latitude" name="professional[address][latitude]" required="required" value="48.7059551" />