Skip to content

Instantly share code, notes, and snippets.

View basiclines's full-sized avatar

Ismael Canal basiclines

View GitHub Profile
@basiclines
basiclines / JsBuild
Created May 14, 2012 14:53
Deletes tabs/line breaks/extra white spaces in the html
javascript:(function(){var%20b=document.getElementsByTagName('body')[0];b.innerHTML=b.innerHTML.replace(/\t+|\n+|\r+/g,'');})()
@basiclines
basiclines / ReCSS
Created May 14, 2012 14:54
Reload CSS files in the current webpage
javascript:void(function(){var%20i,a,s;a=document.getElementsByTagName('link');for(i=0;i%3Ca.length;i++){s=a[i];if(s.rel.toLowerCase().indexOf('stylesheet')%3E=0&&s.href)%20{var%20h=s.href.replace(/(&|%5C?)forceReload=\d+/,'');s.href=h+(h.indexOf('?')%3E=0?'&':'?')+'forceReload='+(new%20Date().valueOf())}}})();
@basiclines
basiclines / CSS units parser
Created October 31, 2012 10:30
JS for parsing CSS numeric values followed by 'rem' unit and perform math operations over it
//Open the file directly in the browser and run this script from the console
//Assumptions: The browser uses a <pre/> tag for showing the CSS code
var file = document.querySelector("pre");
var fileContent = file.innerHTML;
var newContent = fileContent.replace(/([\d.]+)(rem)/g, function(m){
var measure = parseFloat(m.split("rem")[0]);
var newMeasure = measure / 1.6;
@basiclines
basiclines / gist:4195744
Created December 3, 2012 15:32
Find CSS rules that uses 'px' in all the .css files
find myappdir/ -name *.css | xargs grep "px" > ~/Desktop/px-myapp.txt
@basiclines
basiclines / rest.js
Last active December 10, 2015 17:18
NodeJs API server that returns the content of the url
// CURL
var util = require('util');
var exec = require('child_process').exec;
// API RESPONSE
var http = require('http');
var sys = require('sys');
var server = http.createServer(function(req, res) {
res.writeHead(200, {
@basiclines
basiclines / mergeMyImages.sh
Created January 23, 2013 17:27
Used for automatically choose remote images files for resolving conflicts in Git and keeps logs of all that images changes
# Script used for automatically choose remote images files for resolving conflicts in Git
# You need your working copy to be in merging status
# Define main folders
LOG_FOLDER="git_log/"
STATUS_FILE=$LOG_FOLDER"raw_status.txt";
BOTH_FILE=$LOG_FOLDER"both_modified.txt";
THEIRS_FILE=$LOG_FOLDER"theirs_modified.txt";
THEIRS_NEWFILE=$LOG_FOLDER"theirs_new.txt";
THEIRS_DELETIONSFILE=$LOG_FOLDER"theirs_deleted.txt";
@basiclines
basiclines / raspberry_installer.sh
Last active April 6, 2016 15:12
Raspberry distros installer script
#!/bin/bash
diskutil list
# Grab your disk location, i'm using /disk2
diskutil unmountDisk /dev/disk2
sudo dd if=/dev/zero of=/dev/rdisk2 bs=1024
sudo dd if=OpenELEC-RPi2.arm-6.0.3.img of=/dev/rdisk2 bs=4m
sync
diskutil unmountDisk /dev/disk2
@basiclines
basiclines / git_move_batch
Created September 1, 2016 10:17
Performs a git move command in a batch of files by renaming file extension
#!/bin/bash
for file in source/*.html.twig; do
git mv "$file" "`basename "$file" .html.twig`.tpl.html"
done
@basiclines
basiclines / remove_git_submodules
Created October 11, 2017 13:19
Safely remove git submodules
#!/bin/bash
mv location/module_name location/module_name_2
git submodule deinit -f -- location/module_name
git rm -f location/module_name
rm -rf location/module_name_2
@basiclines
basiclines / download_images.js
Created October 17, 2017 07:32
NodeJS script to download a batch of images one by one
var fs = require('fs'),
request = require('request');
images = require('./images') // Array of images urls
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};