Skip to content

Instantly share code, notes, and snippets.

View jotaelesalinas's full-sized avatar

José Luis Salinas jotaelesalinas

  • The Hague, Netherlands
View GitHub Profile
/*
* Sets the zoom to make the "wrapper" element fit the width of the page.
*
* $element is either a jQuery object -the wrapper- or directly the width of the wrapper in pixels.
* margin_perc (optional) is the percentage that will be left at both sides
* max_ratio (optional) is an upper limit to the zoom ratio
*
* This function does nothing if the original or the resulting width of the wrapper is greater than the <html> element.
* Dependencies: jQuery (any version will do)
*
@jotaelesalinas
jotaelesalinas / runcommand.py
Created May 12, 2016 23:20
Runs an external command in Python and returns exit code, stdout and stderr contents.
# runcommand.py
# Handy function that executes an external command in the shell
# and returns 3 values: exit code of the command, its standard output
# and its error output.
# If you run the script directly, an example is provided:
# first it will run a successful command and then one with errors
# (you may want to modify them if not running a Unix system).
import subprocess
@jotaelesalinas
jotaelesalinas / git-squash.bat
Last active April 7, 2021 17:05
Easy git-squash (merges last N commits in one)
@echo off
if "%1"=="" goto blank
echo Squashing %1 commits...
git reset --soft HEAD~%1
git log --format=%%B%%n --reverse "HEAD@{1}" -n %1 > _msg.txt
git commit -t _msg.txt
del _msg.txt
echo Done!
@jotaelesalinas
jotaelesalinas / restart-ais.sh
Last active October 11, 2017 10:48
Installs PHP 7.1, node.js 7.x and git in Ubuntu 14.04
#!/bin/bash
# set locale to utf8
sudo apt-get install -y language-pack-en-base
# add php7 repo
sudo LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php
# adding key for nodejs repo
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280
# add nodejs 7 repo
@jotaelesalinas
jotaelesalinas / clean-tplus.js
Last active October 1, 2018 12:00
Clean tplus tutorials
var remove = [
'.global-nav',
'.avert',
'.content-heading',
'.content-banner__content-breadcrumb',
'.content-author',
'.post__footer',
'.avert--sticky',
'.layout__sidebar',
'.market-highlight',
var e = document.querySelector('.site-header');
e.parentElement.removeChild(e);
e = document.querySelector('.site-footer');
e.parentElement.removeChild(e);
e = document.querySelector('.blog-post__comments');
e.parentElement.removeChild(e);
e = document.querySelector('.social-media-links');
e.parentElement.removeChild(e);
e = document.querySelector('.blog-post');
e.style.maxWidth = 'inherit';
@jotaelesalinas
jotaelesalinas / ml-ssa-birthnames-download.php
Created September 30, 2017 15:11
Download birthname data from the Social Security Agency
<?php
// composer require guzzlehttp/guzzle jotaelesalinas/php-rwgen
require 'vendor/autoload.php';
define('DATA_DIR', dirname(__FILE__) . '/data');
$states = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'];
$year_init = 1960;
$year_end = 2016;
var selectors = [
'.metabar'
, 'main > article > header'
, '.js-stickyFooter'
, '.supplementalPostContent'
, '.js-postFooterPlacements'
, 'footer > .container > section'
, '.postActions'
, '.postPromotionWrapper'
, '.js-postFooterPlacements'
var selectors = [   '.SidebarMenu' , '.ActionBar' , '.TitleBar' , '.SidebarSocial' , '.social__top' , '.social__bottom'];
var e = false;for ( var i = 0, l = selectors.length; i < l; i++ ) { while (e = document.querySelector(selectors[i])) {  e.parentElement.removeChild(e);  }}
e = document.querySelectorAll('.Main');for ( var i = 0, l = e.length; i < l; i++ ) { e[i].style.margin = '2em';}
e = document.querySelectorAll('.Tutorial');for ( var i = 0, l = e.length; i < l; i++ ) { e[i].style.margin = '0'; e[i].style.padding = '0'; e[i].style.border = '0'; e[i].style.maxWidth = 'inherit';}
e = document.querySelector('body');e.style.backgroundImage = 'none';e = document.querySelector('body');e.style.backgroundColor = '#fff';
@jotaelesalinas
jotaelesalinas / read_from_console.php
Created January 16, 2018 10:05
PHP read from console
function read_from_console ($prompt) {
if ( function_exists('readline') ) {
$line = trim(readline($prompt));
if (!empty($line)) {
readline_add_history($line);
}
} else {
echo $prompt;
$line = trim(fgets(STDIN));
}