Skip to content

Instantly share code, notes, and snippets.

import subprocess
ps = Popen(['cmd', 'arg1', 'arg2'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, env={'variable' : value}, shell=False)
ps.communicate('input\n')
if ps.wait():
print 'Failed'
import urllib2
import cookielib
cookiejar = cookielib.LWPCookieJar()
cookies = urllib2.HTTPCookieProcessor(cookiejar)
opener = urllib2.build_opener(cookies)
# UA in next line is a bit old
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB;rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9')]
page = opener.open(url)
lines = page.readlines()
@Serpens
Serpens / 3D plot in Python.py
Last active November 16, 2015 12:50
3D plot in Python
fig=pylab.figure()
ax = mpl_toolkits.mplot3d.axes3d.Axes3D(fig)
for i in xrange(len(array)):
ax.plot([i] * 512, numpy.arange(0, 512), zs=array[i])
pylab.show()
@Serpens
Serpens / Zsh - show command execution time.sh
Last active November 16, 2015 12:43
Show execution time for commands that run for longer than 60 seconds.
note_remind=0
note_ignore="yes"
note_command="?"
note_report()
{
echo ""
echo "note_report: $note_command completed in $1 seconds"
}
@Serpens
Serpens / article.tex
Last active November 16, 2015 12:40
basic LaTeX article template
\documentclass[a4paper,12pt,titlepage,twocolumn]{article}
\usepackage{latexsym}
\usepackage[T1,plmath,MeX]{polski}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{textcomp}
\pagestyle{plain}
@Serpens
Serpens / pushbullet.sh
Last active January 12, 2016 08:28
Pushbullet from Bash
#!/bin/bash
curl --header 'Authorization: Bearer API_KEY_HERE' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary "{\"type\": \"note\", \"title\": \"$1\", \"body\": \"$2\"}"

Keybase proof

I hereby claim:

  • I am serpens on github.
  • I am serpens (https://keybase.io/serpens) on keybase.
  • I have a public key whose fingerprint is 160D 65F8 8666 A69B D18F 0286 F4B5 09BD 6E75 E91C

To claim this, I am signing this object:

@Serpens
Serpens / gist:0f26fbdd3b77b25f09ad
Last active November 16, 2015 12:40
Python script directory
SCRIPT_DIRNAME = os.path.dirname(__file__)
PARENT_DIRNAME = os.path.abspath(os.path.join(DIRNAME, os.path.pardir))
@Serpens
Serpens / pkg_version.py
Created November 16, 2015 14:12
Check Python package version
import pkg_resources
pkg_resources.get_distribution("pkg_name").version
@Serpens
Serpens / script_dir.sh
Created November 16, 2015 14:15
Bash - get script directory.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # cd & pwd to get full name (not ".") in all cases