Skip to content

Instantly share code, notes, and snippets.

View jpetitcolas's full-sized avatar

Jonathan Petitcolas jpetitcolas

View GitHub Profile
@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 / 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 / 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 / javascript.json
Created March 5, 2018 09:56
React Functional Component Visual Code Snippet
{
"Create new functional component": {
"prefix": "_compo",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"",
"export const $1 = ({$2}) => (",
" $3",
");",
@jpetitcolas
jpetitcolas / Dockerfile
Created December 12, 2017 20:47
Docker configuration for Prestashop
# config/php/Dockerfile
FROM php:7.0-fpm
RUN apt-get update
RUN apt-get install -y zlib1g-dev && docker-php-ext-install -j$(nproc) zip
RUN \
apt-get install -y libpng-dev libjpeg62-turbo-dev libfreetype6-dev && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
docker-php-ext-install -j$(nproc) gd
@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));
const typeFinder = type => function* (params = {}, ref = 'master') {
const search = function* (searchParams) {
const Api = yield initApi;
const reference = ref === 'master' ? Api.master() : ref;
const preparedForm = Api.form('everything')
.ref(reference)
.pageSize(200);
const predicates = [];
@jpetitcolas
jpetitcolas / couvent.js
Created September 22, 2015 12:19
Only French would understand this lib... ;)
// couvent.js - MIT license
Array.prototype.slice.call(document.querySelectorAll('*')).forEach(function (el) {
el.style.display = 'none';
});
@jpetitcolas
jpetitcolas / db-save.sh
Created September 19, 2015 13:14
Dump a Docker-ized database to Amazon S3
#!/bin/bash
# @see http://www.jonathan-petitcolas.com/2015/09/21/dump-docker-ized-database-to-amazon-s3.html
# Configuration
FILENAME="awesomeproject-`date +%Y-%m-%d-%H:%M:%S`.sql"
CONTAINER_NAME="awesomeproject_pgsql"
DUMPS_FOLDER="/home/awesomeproject/dumps"
BUCKET_NAME="awesomeproject-private"
@jpetitcolas
jpetitcolas / Application.js
Created February 27, 2015 10:45
Issue with Babel
import View from "./folder/View";
class Application {
constructor() {
this.view = new View("I'm a view!");
}
sayHello() {
console.log("Hello");
}