Skip to content

Instantly share code, notes, and snippets.

''' This is adapted from an example I found somewhere, if anyone knows what it is let me know and I'll credit the original '''
import threading
import time
import math
import gobject
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
import random
@MercuryRising
MercuryRising / easyalias.py
Last active December 15, 2015 11:09
Easily alias your bashrc file (a 'step through' of making the program)
'''
We are going to make a program that lets us run something like:
python easyalias.py sl ls
or
python easyalias.py I_want_my_python_now python
and adds the alias to our .bashrc file, letting us easily add aliases that persist without directly editing the file.
@MercuryRising
MercuryRising / easyalias.py
Last active December 15, 2015 17:29
Easy aliaser for bash. If you keep navigating to directories to run files, easyalias them.
#!/usr/bin/python
'''
Bash RC aliaser
Usage: easyalias aliasName aliasPath
Outputs: run source ~/.bashrc for commands to take effect
Configuration: If you have a different shell or your bashrc is somewhere other than ~/.bashrc, you'll need to change it.
It wouldn't be a bad idea to use ~/.bash_aliases instead of your bash file directly (changing config will do it).
@MercuryRising
MercuryRising / quick_sort_inplace.py
Created April 14, 2013 07:17
quick sort in place
def quick_sort_partition(sequence, left, right):
'''
In place sorts the subsequence of sequence[left:right]
'''
pivot_value = random.choice(sequence[left:right])
pivot_index = sequence.index(pivot_value)
sequence[pivot_index], sequence[right] = sequence[right], sequence[pivot_index]
@MercuryRising
MercuryRising / gravitytrain.py
Created August 28, 2013 21:19
Hypocycloid Gravity Train
# -*- coding: utf-8 -*-
from math import *
import wolframalpha
client = wolframalpha.Client("YHQ3GK-PT45KT9AHG")
radius = 6367500
circumference = 2*pi*radius
gravitational_constant = 9.8 # m/s2