This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python | |
import serial | |
import time | |
import sys | |
extruderSetPoint = 345 | |
bedSetPoint = 6300 | |
ser = serial.Serial("/dev/ttyUSB0", 115200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup as bs | |
from pyquery import PyQuery as pq | |
from lxml.html import fromstring | |
import re | |
import requests | |
import time | |
def Timer(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2 | |
# Requests is much easier to use than urllib | |
import requests | |
# needed for sys.exit() | |
import sys | |
# Wrap it in a function you can, you might find a use for it later | |
# We're adding subreddit functionality, but still providing a default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import time | |
import random | |
def load_file(fp, fpKey, r, expiry): | |
with open(fp, "rb") as f: | |
data = f.read() | |
p = r.pipeline() | |
p.set(fpKey, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import time | |
def cache_or_get(fp, expiry=300, r=redis.Redis(db=5)): | |
''' | |
Input fp: file to cache or get | |
Input expiry: time to expire for file (default 300 seconds) | |
Input r: redis instance (default new instance with db set to 4) | |
Usage: |
NewerOlder