Skip to content

Instantly share code, notes, and snippets.

View beefy's full-sized avatar
✌️

Nate Schultz beefy

✌️
  • Zendesk
  • Philadelphia, PA
  • 09:21 (UTC -04:00)
View GitHub Profile
#include "my.h"
/**
* Prints a number using the length of the string as the base and the contents
* as the alphabet. For example, if you called my_num_base(9, "RTFM"), then
* R = 0, T = 1, F = 2, M = 3. 9 in base 4 is 21 and so the result is printed
* out as "FT".
*
* If char* is NULL or empty, print an error message and return.
* If given unary, repeat alphabet letter the specified number of times.
@beefy
beefy / chess_scrape.py
Last active December 29, 2020 03:56
Scrapes all live chess game PGNs from chess.com and concatenates the resulting files
#!/usr/bin/python
import spynner
import pyquery
import urllib
import os
# author: Nate Schultz
# contact: github.com/beefy
# created: 10/22/16
@jjgrainger
jjgrainger / Vector.js
Last active May 27, 2023 22:59
A simple Vector class in javascript
var Vector = function(x, y) {
this.x = x || 0;
this.y = y || 0;
};
// return the angle of the vector in radians
Vector.prototype.getDirection = function() {
return Math.atan2(this.y, this.x);
};
@evanradcliffe
evanradcliffe / lyricsearch.py
Created July 8, 2016 15:55
Search Genius for the current playing Spotify song.
#!/usr/bin/env python
import webbrowser
import dbus
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify",
"/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus,
"org.freedesktop.DBus.Properties")
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@randyzwitch
randyzwitch / kmeans-loop.R
Created September 17, 2013 17:38
Repeated k-means to calculate elbow graph
#accumulator for cost results
cost_df <- data.frame()
#run kmeans for all clusters up to 100
for(i in 1:100){
#Run kmeans for each level of i, allowing up to 100 iterations for convergence
kmeans<- kmeans(x=dtm, centers=i, iter.max=100)
#Combine cluster number and cost together, write to df
cost_df<- rbind(cost_df, cbind(i, kmeans$tot.withinss))
@evandrix
evandrix / README.md
Created September 11, 2012 00:06
Headless web browsers

Here are a list of headless browsers that I know about:

  • [HtmlUnit][1] - Java. Custom browser engine. JavaScript support/DOM emulated. Open source.
  • [Ghost][2] - Python only. WebKit-based. Full JavaScript support. Open source.
  • [Twill][3] - Python/command line. Custom browser engine. No JavaScript. Open source.
  • [PhantomJS][4] - Command line/all platforms. WebKit-based. Full JavaScript support. Open source.
  • [Awesomium][5] - C++/.Net/all platforms. Chromium-based. Full JavaScript support. Commercial/free.
  • [SimpleBrowser][6] - .Net 4/C#. Custom browser engine. No JavaScript support. Open source.
  • [ZombieJS][7] - Node.js. Custom browser engine. JavaScript support/emulated DOM. Open source.
  • [EnvJS][8] - JavaScript via Java/Rhino. Custom browser engine. JavaScript support/emulated DOM. Open source.
@diosmosis
diosmosis / example.py
Created August 15, 2011 22:41
Python decorator that catches exceptions and logs a traceback that includes every local variable of each frame.
import os
from log_exceptions import log_exceptions
def throw_something(a1, a2):
raise Exception('Whoops!')
@log_exceptions(log_if = os.getenv('MYAPP_DEBUG') is not None)
def my_function(arg1, arg2):
throw_something(arg1 + 24, arg2 - 24)
@j4mie
j4mie / normalise.py
Created August 30, 2010 12:44
Normalise (normalize) unicode data in Python to remove umlauts, accents etc.
# -*- coding: utf-8 -*-
import unicodedata
""" Normalise (normalize) unicode data in Python to remove umlauts, accents etc. """
data = u'naïve café'
normal = unicodedata.normalize('NFKD', data).encode('ASCII', 'ignore')
print normal