Skip to content

Instantly share code, notes, and snippets.

View pelson's full-sized avatar

Phil Elson pelson

View GitHub Profile
@bergantine
bergantine / gist:1171682
Last active July 11, 2023 01:42
Python Image Encoding in Data URI Scheme Base 64. #python #base64
data_uri = open("sample.png", "rb").read().encode("base64").replace("\n", "")
# HTML Image Element
img_tag = '<img alt="" src="data:image/png;base64,{0}">'.format(data_uri)
print img_tag
# CSS Background Image
css = 'background-image: url(data:image/png;base64,{0});'.format(data_uri)
print css
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@ahomu
ahomu / shot.js
Created September 30, 2012 23:28
Create slides(Reveal.js) PNG images using phantomjs
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://localhost:1947/';
page.viewportSize = {
width: 1024,
height: 768
};
page.open(url, function (status) {
//Page is loaded!
var iz, i = 0, queue = {};
@dmcdougall
dmcdougall / xkcd.py
Created October 4, 2012 09:42
XKCD-style graphs in matplotlib
import numpy as np
from matplotlib import rcParams
rcParams['text.usetex'] = False
from matplotlib.backends.backend_agg import FigureCanvasAgg as fc
from matplotlib.figure import Figure
import matplotlib.font_manager as fm
# Function to draw a random function. Yo dawg...
def rand_func():
# Some random Fourier coefficients
@minrk
minrk / SWCDemo.ipynb
Created October 4, 2012 22:32
Demo of hideable hints and scrubbing solutions from IPython notebooks
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pelson
pelson / EIDA50_201211061300_clip2.png
Last active December 19, 2015 00:49
Scipy Presentation 2013: Iris & Cartopy
EIDA50_201211061300_clip2.png
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active October 27, 2024 19:13
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@dan-blanchard
dan-blanchard / .1.miniconda.md
Last active December 11, 2019 22:38
Quicker Travis builds that rely on numpy and scipy using Miniconda

For ETS's SKLL project, we found out the hard way that Travis-CI's support for numpy and scipy is pretty abysmal. There are pre-installed versions of numpy for some versions of Python, but those are seriously out of date, and scipy is not there are at all. The two most popular approaches for working around this are to (1) build everything from scratch, or (2) use apt-get to install more recent (but still out of date) versions of numpy and scipy. Both of these approaches lead to longer build times, and with the second approach, you still don't have the most recent versions of anything. To circumvent these issues, we've switched to using Miniconda (Anaconda's lightweight cousin) to install everything.

A template for installing a simple Python package that relies on numpy and scipy using Miniconda is provided below. Since it's a common s

@lrhache
lrhache / python-selenium-open-tab.md
Last active July 31, 2024 20:57
Python Selenium - Open new tab / focus tab / close tab

On a recent project, I ran into an issue with Python Selenium webdriver. There's no easy way to open a new tab, grab whatever you need and return to original window opener.

Here's a couple people who ran into the same complication:

So, after many minutes (read about an hour) of searching, I decided to do find a quick solution to this problem.

@ozh
ozh / xkcd.css
Created March 12, 2014 09:41
XKCD font
/* font from https://github.com/ipython/xkcd-font
* converted to web font in base64 with
* http://www.fontsquirrel.com
*/
@font-face {
font-family: 'xkcdregular';
src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAFUEABMAAAAAmIwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABqAAAABwAAAAcZzPs3EdERUYAAAHEAAAAHQAAACAAqwAER1BPUwAAAeQAAAUsAAAI6KIfuCpHU1VCAAAHEAAAACwAAAAwuP+4/k9TLzIAAAc8AAAARwAAAGB0yJOSY21hcAAAB4QAAAEcAAAB6qFMdl1jdnQgAAAIoAAAAEgAAABIE5kZd2ZwZ20AAAjoAAABsQAAAmVTtC+nZ2FzcAAACpwAAAAIAAAACAAAABBnbHlmAAAKpAAARK4AAH+Mp+zsDGhlYWQAAE9UAAAALwAAADYD5y0taGhlYQAAT4QAAAAeAAAAJA4xBqpobXR4AABPpAAAAU0AAAH48WoV22xvY2EAAFD0AAAA7AAAAP7KyqwybWF4cAAAUeAAAAAfAAAAIAGbAvduYW1lAABSAAAAAQ4AAAKyORJbEXBvc3QAAFMQAAABIwAAAcgo6S23cHJlcAAAVDQAAADFAAABdD4epAl3ZWJmAABU/AAAAAYAAAAGwE1THwAAAAEAAAAAzD2izwAAAADLsNlAAAAAAM9FcMx42mNgZGBg4ANiCQYQYGJgBMJaIGYB8xgACakAsAAAAHjaVZbfa5tVGMefNOkPejG0v9ReDJXSH/nRNI1tmqZppJSXEkIo4SWU8BJiqCVE29K1Yw6VoTJkypDhnYiUUYoXu5Aio4wxmLPUGTcpMnbjjVf+Fcvx855zlErIkpP3fT/ne77P93lWCYhIr0zJonQsO