Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Petitcolas jpetitcolas

View GitHub Profile
@jpetitcolas
jpetitcolas / pythonizeJsonDump.js
Last active Oct 21, 2020
Pythonise JS JSON dump
View pythonizeJsonDump.js
/*
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 Feb 24, 2020
Getting AWS CloudWatch Insight results from CLI
View snippet.sh
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 Jan 11, 2020
Marking all tickets as completed on an Asana board column
View snippet.js
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 Mar 5, 2018
React Functional Component Visual Code Snippet
View javascript.json
{
"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 Dec 12, 2017
Docker configuration for Prestashop
View Dockerfile
# 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 Apr 13, 2017
Display browser logs in Selenium logs
View gist:4b93a9c9745af5345182fadd0176d298
driver.manage().logs()
.get('browser')
.then(v => v && v.length && console.log(v));
View test.js
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 Sep 22, 2015
Only French would understand this lib... ;)
View couvent.js
// couvent.js - MIT license
Array.prototype.slice.call(document.querySelectorAll('*')).forEach(function (el) {
el.style.display = 'none';
});
@jpetitcolas
jpetitcolas / db-save.sh
Created Sep 19, 2015
Dump a Docker-ized database to Amazon S3
View db-save.sh
#!/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"
View Application.js
import View from "./folder/View";
class Application {
constructor() {
this.view = new View("I'm a view!");
}
sayHello() {
console.log("Hello");
}
You can’t perform that action at this time.