Skip to content

Instantly share code, notes, and snippets.

@rocapp
rocapp / instructions.md
Last active August 29, 2015 14:25 — forked from cmheisel/instructions.md
Kabbage Code Sample

User story

As a Kabbage developer, I want to see how you code a lightweight application, so that I can get a feel for a your skills and strengths.

Acceptance Criteria:

  1. Given a user, when they access your application, then they should be presented with a search box prompting them for a topic
  2. Given a user, when they enter a topic, results from Twitter should be returned
  3. Given a user, when they enter a topic, results from Wikipedia should be returned
  4. Given a user who's performed a search, when they hit the browser's refresh button, results should be refreshed under the same search criteria.
@rocapp
rocapp / imshow_label.py
Last active September 16, 2016 17:32
imshow for labeling raster plots
colors = np.array(colors) # color array (N, 3)
repimg = np.broadcast_to(colors, (nr_neurons, len(colors), 3)) # broadcast the array to split into time axes
for r in range(0, nr_neurons): # iterate through each time axis
bot, top = 0.5+r, 1.5-vspace+r # set the locations of the bottom and top of each imshow extent
ax.imshow(repimg[:, :, :], extent=(0., tspace[-1], bot, top), alpha=0.85, aspect='auto') # call imshow
class StdOutListener(StreamListener):
""" A listener handles tweets that are received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def __init__(self):
self.dat = list()
self.i = 0
def on_data(self, data):
sdat = unicode(data.split('"text":')[1].split(',')[0].replace('"',''))
def do_tweet(auth, tttw=10):
api = API(auth) # connect to Twitter using my authorization info
words = get_words('tweets.txt') # Get words from general tweets
words.extend(get_haikus('haiku.txt')) # Get previously written but un-tweeted haikus
words.extend(get_best('best.txt')) # Get list of "best" tweets
words.extend(get_words('search.txt')) # Get list of specifically searched terms
sdict = make_sdict(words) # Make a dictionary that maps words to their number of syllables
# Make a list of haikus and tweet them every 15 minutes
haik = list()
j = 0
from nltk.corpus import cmudict
d = cmudict.dict()
def nsyl(word):
return [len(list(y for y in x if y[-1].isdigit())) for x in d[word.lower()]]
import numpy as np
from nltk.tokenize import word_tokenize
from nltk import pos_tag
def pick_syl(target):
si = 0
choices = list()
while si != target:
if target-si != 1:
cr = np.random.randint(1, target-si)
def haiku(sdict):
sdict = dict([(sk, sv) for sk, sv in sdict.items() if len(sk) >= 3])
first_5 = choose_words(sdict, 5, 0)
seven = choose_words(sdict, 7, 1)
sec_5 = choose_words(sdict, 5, 2)
first_line = ' '.join(first_5)
second_line = ' '.join(seven)
third_line = ' '.join(sec_5)
hai = ', '.join([first_line, second_line, third_line])
with open('haiku.txt', 'a+') as h:
import numpy as np
from tweepy import API, OAuthHandler
import json
auth = OAuthHandler(consumer_key, consumer_secret) # Connect to twitter via oAuth
auth.set_access_token(access_token, access_token_secret)
api = API(auth)
def get_haikus(api):
def get_best(file):
words = list()
with open(file, 'r') as f:
bf = json.load(f)
sbf = sorted(bf.items(), key=itemgetter(1), reverse=True)
sbf = [bb[0] for bb in sbf]
return sbf[0:int(len(sbf)/2.0)] # chooses the top half
@rocapp
rocapp / get-e2-info
Created April 11, 2023 01:18
Tiny CLI for IDrive E2
#!/usr/bin/env python
import requests
import json
import argparse
import configparser
from pathlib import Path
class AWSConfig:
def __init__(self):