Skip to content

Instantly share code, notes, and snippets.

Riccardo Bartoli rbartoli

Block or report user

Report or block rbartoli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View GIT tips.md

GIT tips

Fetch a file from another branch to the current one

git checkout branch_name -- filename

Unstage all changes but leave files in the working directory untouched

git reset HEAD

Unstage a file

git reset HEAD

@rbartoli
rbartoli / js: sortBy
Last active Aug 29, 2015
JS: Object sort with additional parameters
View js: sortBy
var sort_by;
(function() {
// utility functions
var default_cmp = function(a, b) {
if (a == b) return 0;
return a < b ? -1 : 1;
},
getCmpFunc = function(primer, reverse) {
var dfc = default_cmp, // closer in scope
View Deploy with GIT.md

Deploy your site with GIT

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
    • apache's home directory is /var/www/
View Where is that console.log?
['log', 'warn'].forEach(function(method) {
var old = console[method];
console[method] = function() {
var stack = (new Error()).stack.split(/\n/);
// Chrome includes a single "Error" line, FF doesn't.
if (stack[0].indexOf('Error') === 0) {
stack = stack.slice(1);
}
var args = [].slice.apply(arguments).concat([stack[1].trim()]);
return old.apply(console, args);
@rbartoli
rbartoli / install-pm2.sh
Last active Sep 28, 2016
PM2 installation steps
View install-pm2.sh
# Add safe user
useradd -s /bin/bash -m -d /home/safeuser -c "safe user" safeuser
passwd safeuser
usermod -aG sudo safeuser
# Install PM2
sudo npm install -g pm2
cd project
NODE_ENV=production pm2 start server.js
pm2 startup
@rbartoli
rbartoli / vagrant-bootstrap.sh
Last active Aug 29, 2015
Example bash script provisioner for Ubuntu 14.04.1 (x64)
View vagrant-bootstrap.sh
sudo locale-gen en_GB.UTF-8
sudo addgroup vagrant www-data
# Set timezone (UTC)
echo "Etc/UTC" | sudo tee /etc/timezone && sudo dpkg-reconfigure --frontend noninteractive tzdata
# Update system
sudo apt-get update
sudo apt-get -y dist-upgrade
@rbartoli
rbartoli / js: event delegation
Last active Aug 29, 2015
Vanilla JS event delegation
View js: event delegation
document.getElementById( 'menu' ).addEventListener( 'click', function( event ) {
if( event.target && event.target.nodeName === 'LI' ) {
// Event triggered
}
});
View GIF-Screencast-OSX.md

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

View .gitconfig
[alias]
# View abbreviated SHA, description, and history graph of the latest 20 commits
l = log --pretty=oneline -n 50 --graph --abbrev-commit
# View the current working tree status using the short format
s = status -s
# Show the diff between the latest commit and the current state
d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"
# Commit all changes
cm = !git add -A && git commit -m
# Switch to a branch, creating it if necessary
@rbartoli
rbartoli / create-swap.sh
Created Mar 29, 2015
Linux: create swap file
View create-swap.sh
dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" > /etc/fstab
You can’t perform that action at this time.