Skip to content

Instantly share code, notes, and snippets.

@matiasherranz
matiasherranz / get_extension2
Created September 26, 2014 15:54
Get filename extension function, using a regex. Keep the point.
import re
def get_extension(filename):
regex = re.compile(r'^.*?.(?P<ext>.tar\.gz|.tar\.bz2|.\w+)$')
return regex.match(filename).group('ext')
@matiasherranz
matiasherranz / get_extension.py
Created September 26, 2014 15:52
Get filename extension function, using a regex.
import re
def get_extension(filename):
regex = re.compile(r'^.*?[.](?P<ext>tar\.gz|tar\.bz2|\w+)$')
return regex.match(filename).group('ext')
git conflicts
diff --name-only --diff-filter=U
git config --global alias.conflicts "diff --name-only --diff-filter=U"
@matiasherranz
matiasherranz / gist:6832433
Created October 4, 2013 20:45
Mac OS Beep
beep() {
$@ &amp;&amp; afplay /System/Library/Sounds/Glass.aiff || afplay /System/Library/Sounds/Blow.aiff
}
@matiasherranz
matiasherranz / gist:6832420
Created October 4, 2013 20:44
Ubuntu Beep
beep() {
$@ &amp;&amp; paplay /usr/share/sounds/gnome/default/alerts/glass.ogg || paplay /usr/share/sounds/alsa/Noise.wav
}
# Let's create a list with duplicated elements:
ls = [1,1,1,2,2,1,5,4,3,2,1]
# And let's now remove them in just one line:
l2 = list(set(ls))
# See the result:
@matiasherranz
matiasherranz / gist:6693320
Created September 25, 2013 00:32
Python madness
[matias@MacBookPro]:~$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
... print 'f()'
...
>>> def g():
... print 'g()'
...