Skip to content

Instantly share code, notes, and snippets.

View jpetitcolas's full-sized avatar

Jonathan Petitcolas jpetitcolas

View GitHub Profile
@jpetitcolas
jpetitcolas / gist:5967887
Created July 10, 2013 16:37
Encode/decode a base64 encoded string in PostGreSQL
-- Decoding
SELECT CONVERT_FROM(DECODE(field, 'BASE64'), 'UTF-8') FROM table;
-- Encoding
SELECT ENCODE(CONVERT_TO(field, 'UTF-8'), 'base64') FROM table;
@jpetitcolas
jpetitcolas / snippet.sh
Created February 24, 2020 14:07
Getting AWS CloudWatch Insight results from CLI
aws logs start-query \
--profile [PROFILE] \
--log-group-name [GROUP_NAME] \
--start-time `date --date="-30 minutes" "+%s"` \
--end-time `date "+%s"` \
--query-string 'fields @message | limit 50' \
| jq '.queryId' \
| xargs -I{} aws --profile [PROFILE] logs get-query-results --query-id {} \
| jq '.results | .[][0].value'
@jpetitcolas
jpetitcolas / even-odd-row.twig
Created January 8, 2013 06:29
How to differenciate odd and even rows with 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 January 8, 2013 06:40
Camelize a string in Javascript. Example: camelize("hello_world") --> "HelloWorld"
/**
* 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 / gist:4b93a9c9745af5345182fadd0176d298
Created April 13, 2017 10:01
Display browser logs in Selenium logs
driver.manage().logs()
.get('browser')
.then(v => v && v.length && console.log(v));
@jpetitcolas
jpetitcolas / pythonizeJsonDump.js
Last active October 21, 2020 10:37
Pythonise JS JSON dump
/*
Python and Node don't stringify JSON object the same way.
Python adds some spaces after `:` and `,`, causing some trouble if
you try to compute the same hashes across languages.
Here is a Node function turning a Node generated JSON string into
its Python equivalent.
*/
export const pythonizeJsonDump = (jsonDump) =>
jsonDump.replace(/(?!\B"[^"]*)(:|,)(?![^"]*"\B)/g, '$1 ');
@jpetitcolas
jpetitcolas / parsing-binary-file.go
Last active July 27, 2020 12:40
How to parse a binary file in Go? Snippet based on MoPaQ SC2 replay parsing. Related blog post: http://www.jonathan-petitcolas.com/2014/09/25/parsing-binary-files-in-go.html
package main
import (
"bytes"
"encoding/binary"
"fmt"
"log"
"os"
)
@jpetitcolas
jpetitcolas / snippet.js
Created January 11, 2020 10:50
Marking all tickets as completed on an Asana board column
const COLUMN_NAME = "Deployed to Prod"
var column = [...document.querySelectorAll(".BoardBody-column")].filter(
column =>
column.querySelector('.BoardColumnHeader-name') &&
column.querySelector('.BoardColumnHeader-name').textContent == COLUMN_NAME
)[0]
Array.from(column.querySelectorAll(".BoardCard")).map(card => {
card.querySelector(".BoardCard-dropdownButton").click()
@jpetitcolas
jpetitcolas / pre-commit
Created August 12, 2014 14:54
My standard Git pre-commit hook
#!/bin/sh
#
# Based on http://nrocco.github.io/2012/04/19/git-pre-commit-hook-for-PHP.html post
#
# Do not forget to: chmod +x .git/hooks/pre-commit
BAD_PHP_WORDS='var_dump|die|todo'
BAD_TWIG_WORDS='{{ dump(.*) }}'
EXITCODE=0
@jpetitcolas
jpetitcolas / uncamelize.js
Created January 8, 2013 06:45
How to uncamelize a string in Javascript? Example: "HelloWorld" --> "hello_world"
/**
* 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") {