Skip to content

Instantly share code, notes, and snippets.

View abehmiel's full-sized avatar

Abraham Hmiel abehmiel

View GitHub Profile
@abehmiel
abehmiel / get_tweets.py
Last active June 23, 2017 13:09
Tweet collector for the irony-sarcasm dataset
#!/usr/bin/python3
# For the dataset (tweet ids), visit:
# http://www.romanklinger.de/ironysarcasm/
# this script lives in the same folder as the eight ID tweet identifier csv files.
import tweepy
import json
import math
import pandas as pd
import csv
@abehmiel
abehmiel / roman.lua
Last active September 14, 2017 19:02
Refucktoring: Roman numerals in LUA
--- ●●●●●●●
-- 7 successes / 0 failures / 0 errors / 0 pending : 48.994555 seconds
-- SOURCE: http://rosettacode.org/wiki/Roman_numerals/Decode#Lua
-- SOURCE: http://rosettacode.org/wiki/Roman_numerals/Encode#Lua
-- Tested with the Busted framework for lua (luarocks install busted)
local math = require "math"
function CiceroCiceroCiceroCiceroCiceroCiceroCiceroCiceroCiceroCicero()
@abehmiel
abehmiel / tweet_utils.py
Created July 11, 2017 17:55 — forked from timothyrenner/tweet_utils.py
Python Utilities for Tweets
from datetime import datetime
import string
from nltk.stem.lancaster import LancasterStemmer
from nltk.corpus import stopwords
#Gets the tweet time.
def get_time(tweet):
return datetime.strptime(tweet['created_at'], "%a %b %d %H:%M:%S +0000 %Y")

Twitter autoresponder bot

By Daniel15 (dan.cx) This is a very simple Twitter autoresponder bot. It requires PECL OAuth extension to be installed (run "pecl install oauth", or if on Windows, grab php-oauth.dll. If using cPanel you can install it via WHM). The authentication is designed for command-line usage, it won't work too well via a web browser. You'll have to sign up for an application on Twitter's site to get the consumer key and secret.

Could be modified to be more advanced (match regular expressions to answer questions, etc.)

Questions? See my blog post - http://dan.cx/blog/2011/06/twitter-autoreply-bot-dbznappa

Modified 2013-06-13 - Twitter API 1.0 discontinued, modified to use Twitter API 1.1

@abehmiel
abehmiel / cursor_bot.py
Created July 18, 2017 16:15
Super-simple cursor twitter bot framework
import tweepy
from time import sleep
from creds import *
from random import randint
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
matches = ['Hello world',
@abehmiel
abehmiel / streaming_boy.py
Last active July 18, 2017 19:31
Simple streaming twitter bot with phrase matching
import tweepy
# from time import sleep
from creds import *
from random import randint
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
matches = ["Hello world!","Hello, world","Hello, World!","hello world"]
@abehmiel
abehmiel / ssh-auth.bashrc
Created July 28, 2017 19:38
Prompt for ssh-auth on the first time using terminal after reboot (add to .bashrc)
# from https://unix.stackexchange.com/questions/90853/how-can-i-run-ssh-add-automatically-without-password-prompt
if [ ! -S ~/.ssh/ssh_auth_sock ]; then
eval `ssh-agent`
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
fi
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
ssh-add -l > /dev/null || ssh-add
@abehmiel
abehmiel / test.py
Created July 28, 2017 23:59
AAA test sketch
# from http://jamescooke.info/arrange-act-assert-pattern-for-python-developers.html
# from x import *
def test_reverse():
"""
list.reverse inverts the order of items in a list, in place
"""
greek = ['alpha', 'beta', 'gamma', 'delta']
result = greek.reverse()
@abehmiel
abehmiel / memoize_decorator.py
Created July 29, 2017 19:53 — forked from eriwen/memoize_decorator.py
Memoize Decorator in Python
def memoize(fn):
cache = {}
def wrapper(*args):
try:
return cache[args]
except:
result = fn(*args)
cache[args] = result
return result
return wrapper
@abehmiel
abehmiel / ohe.py
Created August 3, 2017 02:56
One hot encode function (for model-building, keras, etc)
import numpy as np
def one_hot_encode_object_array(arr):
'''One hot encode a numpy array of objects (e.g. strings)'''
uniques, ids = np.unique(arr, return_inverse=True)
return np_utils.to_categorical(ids, len(uniques))
train_y_ohe = one_hot_encode_object_array(train_y)
test_y_ohe = one_hot_encode_object_array(test_y)