Skip to content

Instantly share code, notes, and snippets.

@pavgup
pavgup / twittercompetition.py
Created February 21, 2013 19:10
This is a simple tool that uses two twitter accounts to tweet to each other about something interesting. The data provided must meet certain characteristics (ask me if you have questions) and you need to fill in the appropriate key details, but it should work quite simply.
import twitter
import csv
import string
import time
import random
import sys
pavan = twitter.Api(consumer_key='<REMOVED>',consumer_secret='<REMOVED>',access_token_key='<REMOVED>',access_token_secret='<REMOVED>')
fark = twitter.Api(consumer_key='<REMOVED>',consumer_secret='<REMOVED>',access_token_key='<REMOVED>',access_token_secret='<REMOVED>')
#!/usr/bin/python
import urllib2
import threading
import re
import Queue
import sys
# The fourth URL returns a 403 error which python dies on, so I wrap this grab_ip function with exception handling.
@pavgup
pavgup / PrintPOSTandGET.py
Created April 23, 2014 15:47
This stands up a python http server and receives both POST and GET requests and prints to the console the parameters and values it receives over HTTP. This runs on port 9000 and binds 0.0.0.0, so be careful about firewall settings when testing this.
import BaseHTTPServer
import urlparse
class SimpleHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
if "?" in self.path:
for key,value in dict(urlparse.parse_qsl(self.path.split("?")[1], True)).items():
print key + " = " + value
@pavgup
pavgup / designer.html
Last active August 29, 2015 14:15
designer
<link rel="import" href="../topeka-elements/category-images.html">
<link rel="import" href="../core-icon/core-icon.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@pavgup
pavgup / gist:a5ddb047df6669e138cf
Created March 8, 2015 02:37
Python-poker-network alternative installation on Ubuntu 14.04.1 (and 14.04.2) LTS
# Tried this on an AWS EC2 Ubuntu 14.04.1 (and a dist-upgraded 14.04.2) 64 bit VM
# This is nothing more than a copy and paste thing you can do as ubuntu to get up and running.
# It's definitely not efficient at this point, feel free to make more efficient
sudo apt-get -y update;
sudo echo mysql-server-5.5 mysql-server/root_password password abc123 | sudo debconf-set-selections;
sudo echo mysql-server-5.5 mysql-server/root_password_again password abc123 | sudo debconf-set-selections;
sudo apt-get -y install build-essential checkinstall git-core mysql-server \
python-pip python-twisted python-mysqldb \
python-mysqldb-dbg memcached python-memcache \
python-simplejson python-cjson python-cjson-dbg \
@pavgup
pavgup / subversion
Created April 20, 2015 23:18
uber fast subversion exports with parallel
svn ls 'https://svn.pavgup.io/svnroot' | parallel svn export 'https://svn.pavgup.io/svnroot/'\{\}
# Nothing clever here. Seeking adventure? Get yourself a couple more layers of the svnroot with more pipes. Definite overkill.
@pavgup
pavgup / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@pavgup
pavgup / net-image-size.sh
Created May 4, 2015 13:18
Before a magical image optimization pipeline kicks off (e.g., imagemin inside grunt/gulp) you'd probably want to know what the size of all your images are. Here's a quick one-liner that grabs a filetype for every file inside your current directory and then awks out the files that *nix is considering an image before finally handing off the file s…
#!/bin/sh
# Before a magical image optimization pipeline kicks off (e.g., imagemin inside
# grunt/gulp) you'd probably want to know what the size of all your images are.
# Here's a quick one-liner that grabs a filetype for every file inside your
# current directory and then awks out the files that *nix is considering an
# image before finally handing off the file size calculations to du.
find . -exec file {} \; | \
awk -F':' '{
if ($2 ~/[Ii]mage|EPS/)
@pavgup
pavgup / backup-all-images.sh
Created May 4, 2015 15:02
Find all images in a directory, create a backup subdirectory in the current directory, and then copy these images to the backup folder. Preparation for keeping track (poorly) of original files that are being optimized.
#!/bin/sh
mkdir backup; \
for file in $(
find . -exec \
file {} \; | \
awk -F':' '{ if ($2 ~/[Ii]mage|EPS/) print $1,"\n"}'| \
sed s/\.//);
do
cp -R -v .$file ./backup/
@pavgup
pavgup / overwrite-images-with-optimized-images.sh
Last active August 29, 2015 14:20
This is a wee bit dangerous when used in isolation. It will search for all files that *nix believes is an image and will then use imagemin (npm install -g imagemin if you need it) to begin optimizing assuming the defaults are worth trusting. This is not lossless. It does make a backup of each file inside the current working directory inside, con…
#!/bin/sh
mkdir backup;
for file in $(
find . -exec \
file {} \; | \
awk -F':' '{ if ($2 ~/[Ii]mage|EPS/) print $1,"\n"}'| \
sed s/\.//);
do
cp -R -v .$file ./backup/;