Skip to content

Instantly share code, notes, and snippets.

View glafarge's full-sized avatar

Guillaume Lafarge glafarge

View GitHub Profile
<form>
<div class="btn-group" data-toggle-name="is_private" data-toggle="buttons" >
<label class="btn btn-default">
<input type="radio" name="private" value="1"> Yes
</label>
<label class="btn btn-default">
<input type="radio" name="private" value="0"> No
</label>>
</div>
<input type="hidden" name="is_private" value="0" />
@glafarge
glafarge / request.sql
Created February 27, 2014 16:40
Find rank of an user based on score
SELECT id, username, score,
FIND_IN_SET(
score, (SELECT GROUP_CONCAT(DISTINCT score ORDER BY score DESC) FROM score)
) as rank
FROM scores;
@glafarge
glafarge / vanilla.md
Last active August 29, 2015 14:06
jQuery vs Vanilla JavaScript

jQuery vs JavaScript

$(document).ready(function() {
  // code…
});
document.addEventListener("DOMContentLoaded", function() {
  // code…
});
@glafarge
glafarge / check_array.js
Created February 10, 2016 17:59
Check if variable is Array
/**
* Check whether an object is Array or not
* @type Boolean
* @param {object} subject is the variable that is
* tested for Array identity check
*/
var isArray = (function () {
// Use compiler's own isArray when available
if (Array.isArray) {
return Array.isArray;
@glafarge
glafarge / cron_dispatcher.php
Created March 31, 2016 11:07
Using CRON with CakePHP 3.x if you want to call a controller/action quickly
<?php
$_SERVER[ 'HTTP_HOST' ] = 'localhost'; // or something like yourdomain.tld
require dirname(__DIR__) . '/config/bootstrap.php';
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\DispatcherFactory;
if(PHP_SAPI == "cli" && $argc == 2) {
@glafarge
glafarge / truncate.sql
Created August 22, 2016 12:57
Disable temporary the SQL check for constraints
SET FOREIGN_KEY_CHECKS = 0; -- Disable foreign key checking.
TRUNCATE TABLE forums;
TRUNCATE TABLE dates;
TRUNCATE TABLE remarks;
SET FOREIGN_KEY_CHECKS = 1; -- Enable foreign key checking.
@glafarge
glafarge / reorder.sql
Created August 22, 2016 13:31
Reincrement field of a MySQL table
SET @pos := 0;
UPDATE table SET position = ( SELECT @pos := @pos + 1 ) ORDER BY id ASC;
/**
* A linear interpolator for hexadecimal colors
* @param {String} a
* @param {String} b
* @param {Number} amount
* @example
* // returns #7F7F7F
* lerpColor('#000000', '#ffffff', 0.5)
* @returns {String}
*/
@glafarge
glafarge / data.xml
Created February 23, 2018 11:44
Find element by text content with XPath in Python
<root>
<element>A</element>
<element>B</element>
</root>
@glafarge
glafarge / update.sql
Created June 12, 2018 14:12
[MySQL] Increment a col with a counter at once
SELECT @i:=0;
UPDATE contacts SET position = @i:=@i+1 WHERE location_id=1 ORDER BY id;