Skip to content

Instantly share code, notes, and snippets.

View zipizap's full-sized avatar

zipizap

View GitHub Profile
@zipizap
zipizap / bckpDir2home.sh
Created September 3, 2010 19:32
Backs up the current directory, in a ZIP file to the HOME folder. Run the script inside the directory that you want to backup
#!/bin/bash
CURR_DIR="$(basename $PWD)"
BCKP_FILE="$HOME"/"$CURR_DIR""_Backup_""$(date +%F_%T)"".zip"
echo "..Starting executing"
echo "..Going to backup the current directory ('$CURR_DIR') into"
echo " $BCKP_FILE"
echo -n "---> Continue [Y/n] ? " && read CONTINUE
[ -z "$(echo $CONTINUE| grep -i 'y')" ] && echo "..Aborting" && exit 1
cd .. && zip -9r $BCKP_FILE "$CURR_DIR" | sed -u 's/^/.... /g'
@zipizap
zipizap / OpenDns_setup_dhclient.conf.sh
Created September 4, 2010 11:59
Script to configure dhclient to use as primary DNS the OpenDns servers
#!/bin/bash
DHCLIENTCONF_FILE="/etc/dhcp3/dhclient.conf"
#Prepend Opendns name-servers into DHCLIENTCONF_FILE
if [ "$(id -u)" -ne 0 ]; then
echo "Must be run as root"
exit 1
fi
if [ "$(egrep '^prepend domain-name-servers' $DHCLIENTCONF_FILE | wc -l)" -ne 0 ]; then
@zipizap
zipizap / hl2_optirun_start.sh
Created March 11, 2012 23:07
Half Life 2, wine and optirun :)
#!/bin/bash
function msg {
# Description:
# This function echoes-with-colors the arguments passed in
# Usage:
# msg 'whatever you want to print :)'
echo -e '\033[33m\033[44m'$@'\033[0m'
}
@zipizap
zipizap / fix_lexmarkX1170scanner_ubuntu11.10.sh
Created August 9, 2012 13:23
Fix to setup Lexmark X1170 scanner on Ubuntu 11.10
# The fix is based on installing an older version of libsane and libsane-extras
# For more info, see [1] and [2]
# [1] http://angel-de-vicente.blogspot.com.es/2012/07/lexmark-x1190-with-ubuntu-1110-64-bits.html
# [2] https://bugs.launchpad.net/ubuntu/+source/xsane/+bug/774475
# [3] http://ubuntuforums.org/showpost.php?p=12159929&postcount=36
#
# To apply the fix, copy/paste the following in a terminal:
# . Uninstall libsane + libsane-extras
sudo apt-get remove libsane libsane-extras
@zipizap
zipizap / gist:4976977
Last active May 26, 2017 04:07
Add user to group, and make changes take effect *without logout/login* using *newgrp* This solution is very limited - it will only update the groups in the current shell session. New shells sessions will not have the groups updated - you can update them manually with this method, or better yet, you can logout/login so that the group update is ma…
# How to add user into group, and make changes take effect *without logout/login*: the *newgrp* command
#
# Do note that this method will only update the groups, in the current shell session (and its child-processes).
# New shell sessions will not have the groups updated - either use this method to update the groups in each shell
# session, or logout/login to make the group update permanent by default
#
# In short:
# $ sudo adduser user_x my_grp
# $ newgrp my_grp && newgrp
#
@zipizap
zipizap / pass_fd_unixsocket.rb
Last active December 20, 2015 00:19
Pass a file-descriptor between 2 processes, using UnixSockets - (MRI vs Jruby limitations)
require 'socket'
require 'spoon'
# I made this code to experiment with 2 things:
# 1) Use the 'spoon' gem and Spoon.spawnp as a poor-man-substitute of a normal fork
# 2) pass a file-descriptor over unix-sockets, from a parent process to a child process
#
# Jruby cannot .fork() as MRI Ruby... it seems the alternative is 'spoon' gem and its
# spawn/spawnp methods.
# Fork is not the same as spawning: basically fork will copy to a child process all
@zipizap
zipizap / _usr_bin_xdg-open
Created August 3, 2013 19:58
/usr/bin/xdg-open - patched to open magnet: links with transmission
#!/bin/sh
#---------------------------------------------
# xdg-open
#
# Utility script to open a URL in the registered default application.
#
# Refer to the usage() function below for usage.
#
# Copyright 2009-2010, Fathi Boudra <[email protected]>
# Copyright 2009-2010, Rex Dieter <[email protected]>
@zipizap
zipizap / rpm_resume.svg
Created October 9, 2013 15:00
RPM resume Edit/improve/correct it with Inkscape, and leave a comment in my blog: http://zipizap.wordpress.com/2013/10/09/rpm-resume-diagram/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zipizap
zipizap / gist:6935276
Created October 11, 2013 14:10
Bash ternary-like comparisons
# condition && command-if-true || command-if-false
#
# CAUTION: condition && ... || ... works, but
# condition || ... && ... does NOT work!
#
$ [[ "your" == "condition" ]] && echo "executed if true" || echo "executed if false"
executed if false
$ [[ "your" == "your" ]] && echo "executed if true" || echo "executed if false"
executed if true
#!/bin/bash
# capture SIGINT (emitted when CTRL-C)
function handler__CtrlC {
echo "------- handler_CtrlC -------"
echo ">> Control-C was pressed. Exiting"
exit 1
}
trap handler__CtrlC SIGINT
echo "Handler for CTRL-C is defined - press CTRL-C or wait 5 seconds to continue"