Skip to content

Instantly share code, notes, and snippets.

View glafarge's full-sized avatar

Guillaume Lafarge glafarge

View GitHub Profile
@glafarge
glafarge / update.sql
Created April 14, 2021 10:55
SQL / Bulk update date columns
# SQL Methods to randomize and update Wordpress posts-dates at once
# ======================================
# First method :
# ======================================
SET @STARTDATE = "2021-01-01";
SET @SETDATE = "2021-04-01 00:00:00";
UPDATE `wp_posts`
@glafarge
glafarge / filter.php
Created June 3, 2020 11:15
Finding specific messages from CakePHP 3.x logs
<?php
$log = file_get_contents('./src/logs/error-test.log');
// Find all logs messages matching a pattern to process them, filter them out...
$exceptions = ['RecordNotFoundException', 'MissingRouteException', 'MissingActionException', 'MissingControllerException'];
$words = implode($exceptions, '\b|');
$re = '/^.*(\b'.$words.'\b)\][\s\S]+?(?=\n\n)/m';
preg_match_all($re, $log, $matches, PREG_SET_ORDER, 0);
// All found entries in $matches
@glafarge
glafarge / encode.js
Created October 17, 2019 12:45
Hide text in string using unicode
/* Code from https://syllab.fr/projets/experiments/wutf/ */
var placeholders = [
"Hey ! What's up ?",
"Hello !?",
"Yop !",
"You're here ?",
"Got a second ?",
"I need you man",
"Plans for the week end ?",
@glafarge
glafarge / app.js
Last active May 23, 2023 08:57
Barba.js / Transitions and views
const barba = require('@barba/core');
const anime = require('animejs');
const Home = require('./views/home');
const WhoWeAre = require('./views/whoweare');
class App {
init() {
barba.init({
transitions: [{
@glafarge
glafarge / mapbox-hover-click.js
Created December 6, 2018 10:09
Mapbox markers hover + click
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/****/********',
center: [-0.579180, 44.837788],
zoom: 12.0
});
map.on('load', function() {
// ====================================
@glafarge
glafarge / promise.js
Created November 16, 2018 08:26
Avoid flickering spinner
var spinner = document.querySelector('.spinner');
var content = document.querySelector('.content');
var refreshButton = document.querySelector('.refreshButton');
function networkRequest() {
return new Promise((resolve, reject) => {
const requestTime = 200; // request duration (for simulation) => 200ms
setTimeout(resolve, requestTime, { payload: { 'foo': 'bar' } });
});
@glafarge
glafarge / update.sql
Created June 13, 2018 17:43
Change all tables prefixes in database at once
SET @database = "database_name";
SET @old_prefix = "old_prefix_";
SET @new_prefix = "new_prefix_";
SELECT
concat(
"RENAME TABLE ",
TABLE_NAME,
" TO ",
replace(TABLE_NAME, @old_prefix, @new_prefix),
@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;
@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>
/**
* 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}
*/