Skip to content

Instantly share code, notes, and snippets.

View vgoklani's full-sized avatar

Vishal Goklani vgoklani

View GitHub Profile
@endolith
endolith / Perfect_FFT.py
Last active June 16, 2023 08:25
Perfect FFT
from numpy import linspace, cos, pi, absolute
from numpy.fft import fft, fftfreq, fftshift
import matplotlib.pyplot as plt
# Sampling rate
fs = 64 # Hz
# Time is from 0 to 1 seconds, but leave off the endpoint, so
# that 1.0 seconds is the first sample of the *next* chunk
length = 1 # second
ACCESS_KEY='YOUR AMAZON API KEY'
SECRET='YOUR AMAZON SECRET'
BUCKET_NAME='database_backup_bucket' #note that you need to create this bucket first
from boto.s3.connection import S3Connection
from boto.s3.key import Key
def save_file_in_s3(filename):
conn = S3Connection(ACCESS_KEY, SECRET)
bucket = conn.get_bucket(BUCKET_NAME)
@puffnfresh
puffnfresh / google_prediction.py
Created May 20, 2010 02:42
Python library for the Google Prediction API
#!/usr/bin/env python
"""
This module provides an interface to the Google Prediction API.
"""
import json
import numbers
import urllib
import urllib2
@irr
irr / gist:466742
Created July 7, 2010 14:11
running-tornado-in-production
# from: http://www.tornadoweb.org/documentation
# running-tornado-in-production
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
"""
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage.
Do not forget to replace YOURSERVER by the correct value.
Keep in mind that you need the *very latest* version of your web browser.
You also need to add Jacob Kristhammar's websocket implementation to Tornado:
Grab it here:
http://gist.github.com/526746
Or clone my fork of Tornado with websocket included:
http://github.com/pelletier/tornado
Oh and the Pub/Sub protocol is only available in Redis 2.0.0:
@mblondel
mblondel / lda_gibbs.py
Last active October 9, 2023 11:31
Latent Dirichlet Allocation with Gibbs sampler
"""
(C) Mathieu Blondel - 2010
License: BSD 3 clause
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""
@kwellman
kwellman / gist:632442
Created October 18, 2010 15:44
lxml_readability.py
"""An lxml Port of Nirmal Patel's port (http://nirmalpatel.com/fcgi/hn.py) of
Arc90's Readability to Python.
"""
import re
from lxml.html import fromstring, tostring
from lxml.html.clean import Cleaner
NEGATIVE = re.compile('comment|meta|footer|footnote|foot')
POSITIVE = re.compile('post|hentry|entry|content|text|body|article')
@kwellman
kwellman / gist:632478
Created October 18, 2010 16:00
readability_benchmarks.py
"""Quick and dirty benchmarking for readability functions.
"""
import re, time, os, json
from urllib import urlopen
from hn import grabContent
from lxml_readability import extract
import socket
socket.setdefaulttimeout(30)
@alextp
alextp / fast_svd.py
Created November 4, 2010 13:12
Gunnar Martinsson's fast svd
import numpy as np, numpy.linalg as linalg
def fast_svd(M, k):
p = k+5
Y = np.dot(M, np.random.normal(size=(M.shape[1],p)))
Q,r = linalg.qr(Y)
B = np.dot(Q.T,M)
Uhat, s, v = linalg.svd(B, full_matrices=False)
U = np.dot(Q, Uhat)
return U.T[:k].T, s[:k], v[:k]
@ewilderj
ewilderj / friends.py
Created December 9, 2010 18:19
Make a graph of your social network from those you follow
# a messy hack written by Edd Dumbill. http://twitter.com/edd
# You may need to rerun this script if you hit a Twitter Error because you
# use up API rate limiting. That's why we pickle the results, so we can resume
# where we left off.
# get the twitter module using 'easy_install twitter'
from twitter.api import Twitter, TwitterError
from twitter.oauth import OAuth