Skip to content

Instantly share code, notes, and snippets.

@frantzmiccoli
frantzmiccoli / envcheck
Created March 30, 2020 20:22
Small naive script to look for missing variables from a reference .env file to another
#!/usr/bin/env python3
# Usage:
# envcheck source/.env.template source/.env
import sys
def main():
variables_sets_list = _get_variables_set_list()
@frantzmiccoli
frantzmiccoli / Duplicate a template folder in Google Drive using Google Apps Script
Last active February 11, 2020 07:37
Funnily enough you can't duplicate a folder which contains Google Documents
function duplicateRootFolder() {
var templateFolder = DriveApp.getFolderById('PUT YOUR TEMPLATE FOLDER ID HERE (FROM YOUR BROWSER URL)');
var targetParent = DriveApp.getFolderById('PUT YOU PARENT FOLDER ID HERE (FROM YOUR BROWSER URL)');
duplicateFolder(templateFolder, targetParent, false);
}
function duplicateFolder(templateFolder, targetParent, useTemplateName) {
var newFolderName = templateFolder.getName();
echo "<?php echo password_hash('hello', PASSWORD_DEFAULT); echo \"\n\";" > test.php; php test.php; php test.php
@frantzmiccoli
frantzmiccoli / localsync
Last active May 30, 2019 08:16
Dirty little script
#!/usr/local/bin/python --
# -*- coding: utf-8 -*-
from paver.easy import sh
import os
import sys
clear_flag = '--clear'
def local_sync():
@frantzmiccoli
frantzmiccoli / associative-sort.php
Created December 10, 2018 15:25
Just a quick demo highlighting that PHP doesn't preserve same-value keys order while running an associative sort
<?php
$a = [];
$threshold = 120;
while (count($a) < 400) {
$v = count($a) > $threshold ? 'a' : 'b';
$a[] = $v;
}

Keybase proof

I hereby claim:

  • I am frantzmiccoli on github.
  • I am frantzmiccoli (https://keybase.io/frantzmiccoli) on keybase.
  • I have a public key ASAiqAa7ifmI-TxwqgucIKM8TbsMEkNDJwDaGPuzmtzMZwo

To claim this, I am signing this object:

@frantzmiccoli
frantzmiccoli / filtered-cities.zsh
Last active August 29, 2015 14:05
Cities filtered by size
# Data source https://www.maxmind.com/en/worldcities
# Using https://github.com/Russell91/pythonpy
# We first extract the cities with more than 500000 inhabitants
# We then filter those in relevant countries
# We generate a string close to json from the output
cat worldcitiespop.txt|py -fx --i '(int(x.split(",")[4]) > 500000)'|\
py -fx "x.split(',').pop(0) in ['us', 'it', 'es', 'pt', 'gb', 'ie', 'is', 'it', 'fr', 'ca', 'be', 'de', 'at', 'dk', 'se', 'fi', 'nl', 'no', 'ch', 'en','lu', 'pl']" |\
py -x "json.dumps({'name': x.split(',')[2], 'latitude': float(x.split(',')[5]), 'longitude': float(x.split(',')[6])}, indent=4, sort_keys=True)+','"
@frantzmiccoli
frantzmiccoli / richvspoorurbanareas.js
Last active August 29, 2015 14:05
Splitting world's biggest urban area between rich and poor to compute a sum of those population.
// Run me on http://en.wikipedia.org/wiki/List_of_metropolitan_areas_by_population
// from http://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery
var getTextNodesIn = function($el) {
return $($el.find(":not(iframe)").addBack().contents().filter(function() {
return this.nodeType == 3;
}).get(0)).text();
};
var rowsSelector = '#bodyContent .sortable.wikitable.jquery-tablesorter tr',
@frantzmiccoli
frantzmiccoli / extractdatafrombiggestcities in the world
Last active August 29, 2015 14:05
A small script that extract population and data from Wikipedia's list of biggest cities, it can be easily adapted for other pages and other informations.
// Run me in your console on http://en.wikipedia.org/wiki/List_of_cities_proper_by_population
// from http://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery
var getTextNodesIn = function($el) {
return $($el.find(":not(iframe)").addBack().contents().filter(function() {
return this.nodeType == 3;
}).get(0)).text();
};
var rowsSelector = '#bodyContent .sortable.wikitable.jquery-tablesorter tr',
@frantzmiccoli
frantzmiccoli / imgccsearch
Last active July 6, 2016 12:56
Looking at creative commons pictures and tired of switching doing the same things to test all licenses and all sites? This small script is for you. It looks on 500px, Flickr and many cool other ones
#!/usr/bin/env zsh
# Usage: 'imgccsearch "beautiful pictures"'
term=$1
open "https://500px.com/search?q=$term&type=photos&ccLicense=by&sort=relevance"
open "https://500px.com/search?q=$term&type=photos&ccLicense=by-nc&sort=relevance"
open "https://500px.com/search?q=$term&type=photos&ccLicense=by-sa&sort=relevance"
open "https://500px.com/search?q=$term&type=photos&ccLicense=by-nd&sort=relevance"
open "https://500px.com/search?q=$term&type=photos&ccLicense=by-nc-sa&sort=relevance"