Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
!In the mood

Mateus Caruccio caruccio

💭
!In the mood
View GitHub Profile
@caruccio
caruccio / bash-named-param
Created Apr 24, 2012
Named parameters in bash
View bash-named-param
# 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 Apr 24, 2012
Pattern substitution
View bash-pattern-subst
$ 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 Jun 12, 2012
Automatic remote download movies from http://movies.io (flexget + transmission)
View config.yml
## 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 Jul 5, 2012
Extract variable value from file
View gist:3056826
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 Sep 22, 2012
metattuple - recursively creating a namedtuple class from a dict object using a metaclass
View metatuple.py
''' 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 Sep 24, 2012
What does 'pythonic' means?
View pythonic.py
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 Nov 26, 2012
Setup xorg synaptics on my Dell Inspiron 14Z 5423
View xorg-synaptics.conf
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 Aug 3, 2016
Shell variable substitution from within a file.
View var-file-subst.sh
##
# 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 Nov 16, 2020
Path manipulation with bash vars
View bash-path-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 Jan 8, 2013
RedHat Openshift error codes (extracted from source files - grep+python). Neither comprehensive or 100% correct, but it is a start...
View rh-openshift-error-codes.txt
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}'"