Skip to content

Instantly share code, notes, and snippets.

View caruccio's full-sized avatar
😐
state = not in mood

Mateus Caruccio caruccio

😐
state = not in mood
View GitHub Profile
@caruccio
caruccio / bash-named-param
Created April 24, 2012 03:25
Named parameters in bash
# Do you like python named parameters (kvargs) ?
# Well, you can have it in bash too!!
$ function myfunc() { local $*; echo "foo=$foo, bar=$bar"; }
$ myfunc bar=world foo=hello
foo=hello, bar=world
@caruccio
caruccio / bash-pattern-subst
Created April 24, 2012 18:44
Pattern substitution
$ VAR='XOXOXOX'
$ echo ${VAR/X/.} ## first occurence only (anywhere)
.OXOXOX
$ echo ${VAR//X/.} ## all occurences
.O.O.O.
$ VAR='OXOXOX'
$ echo ${VAR/#X/.} ## first occurence (only if beginning match)
OXOXOX
@caruccio
caruccio / config.yml
Created June 12, 2012 01:47
Automatic remote download movies from http://movies.io (flexget + transmission)
## 1 - Create an account in http://movies.io and setup a RSS for your movies
####
## 2 - Install and configure flexget
####
$ sudo easy_install flexget
$ cat <<EOF > ~/.flexget/config.yml
feeds:
movies.io:
@caruccio
caruccio / gist:3056826
Created July 5, 2012 22:18
Extract variable value from file
This should extract the value of a variable from a text file.
It works fine with bash/sh and makefile variables.
Had to use 2 sed()s to deal with name='value' cases.
Fixes are welcome.
$ VAR_NAME=PREFIX
$ sed --version
GNU sed version 4.1.5
$ cat filename.conf | \
sed -ne \
@caruccio
caruccio / metatuple.py
Created September 22, 2012 04:49
metattuple - recursively creating a namedtuple class from a dict object using a metaclass
''' metatuple - Recursive namedtuple from arbitrary dict
After 2 hours of intensive coding and some tequila sips I found
a "simple" solution to create a namedtuple from any dictionary,
recursivelly creating any necessary namedtuple.
Probably there are tons of easiest ways of doing that, like some
well documented method or standart function in the python library,
but that wouldn't be fun.'''
@caruccio
caruccio / pythonic.py
Created September 24, 2012 15:04
What does 'pythonic' means?
for i, j in { 'a': 1, 'b': 2 }.iteritems():
print i, j
for i, j in [ ('a', 1), ('b', 2) ]:
print i, j
@caruccio
caruccio / xorg-synaptics.conf
Created November 26, 2012 22:09
Setup xorg synaptics on my Dell Inspiron 14Z 5423
Section "InputDevice"
Identifier "touchpad"
Driver "synaptics"
Option "LeftEdge" "1766"
Option "RightEdge" "5382"
Option "TopEdge" "1645"
Option "BottomEdge" "4563"
Option "FingerLow" "25"
Option "FingerHigh" "30"
Option "FingerPress" "256"
@caruccio
caruccio / var-file-subst.sh
Last active August 3, 2016 15:44
Shell variable substitution from within a file.
##
# Just found the amazing builtin 'mapfile', perfect
# for substitution variable inside a file by its values.
##
mateus@mateus:/tmp$ cat input.txt
a = $a
b = $b
mateus@mateus:/tmp$ echo a=$a, b=$b
a=1, b=2
@caruccio
caruccio / bash-path-vars
Last active December 28, 2023 22:47
Path manipulation with bash vars
$ FILE=/some/path/to/file.txt
###################################
### Remove matching suffix pattern
###################################
$ echo ${FILE%.*} # remove ext
/some/path/to/file
$ FILE=/some/path/to/file.txt.jpg.gpg # note various file exts
@caruccio
caruccio / rh-openshift-error-codes.txt
Created January 8, 2013 00:36
RedHat Openshift error codes (extracted from source files - grep+python). Neither comprehensive or 100% correct, but it is a start...
SHOW_APPLICATION:
404 Not Found:
101: "Application '#{id}' not found"
127: "Domain '#{domain_id}' not found"
UPDATE_CARTRIDGE:
404 Not Found:
163: "Cartridge '#{cartridge_name}' for application '#{app_id}' not found"
101: "Application '#{app_id}' not found for domain '#{domain_id}'"