Skip to content

Instantly share code, notes, and snippets.

@bshyong
bshyong / fb_studious_student.rb
Created January 9, 2011 06:55
my solution to facebook's hacker cup 'studious student' problem
# (c) 2010 Benjamin Shyong
#
# Studious Student
# You've been given a list of words to study and memorize. Being a diligent student of language and the arts, you've decided to not study them at all and instead make up pointless games based on them. One game you've come up with is to see how you can concatenate the words to generate the lexicographically lowest possible string.
# Input
# As input for playing this game you will receive a text file containing an integer N, the number of word sets you need to play your game against. This will be followed by N word sets, each starting with an integer M, the number of words in the set, followed by M words. All tokens in the input will be separated by some whitespace and, aside from N and M, will consist entirely of lowercase letters.
# Output
# Your submission should contain the lexicographically shortest strings for each corresponding word set, one per line and in order.
var x = 0;
var y = 0;
var xDirection = 1;
var yDirection = 1;
var canvas = null;
var context2D = null;
var background = new Image();
background.src = "bg.gif";
window.onload = init;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Binary Cat</title>
<script type="text/javascript" src="binary_cat.js"></script>
<style type="text/css">
body { font-family: Arial, Helvetica, sans-serif;}
</style>
</head>
<body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Canvas 1</title>
<script type="text/javascript" src="canvas1.js"></script>
<style type="text/css">
body { font-family: Arial, Helvetica, sans-serif;}
</style>
</head>
<body>
@bshyong
bshyong / jqueryUI autocomplete example.js
Created August 29, 2012 19:44
Jquery UI autocomplete example
$.ui.autocomplete, {
_renderMenu: function( ul, items ) {
// use this to manipulate the entire array of results
// if you overwrite this method, make sure to call _renderItem for each item
// or else the individual items will not render, only the menu will render
// example below.
var self = this;
$.each(items, function(index, item){
self._renderItem(ul, item);
}
@bshyong
bshyong / index.html
Created July 3, 2013 03:08
A CodePen by Andreas Gillström. Telecast Hover - Idea from http://drbl.in/hDjU
<h4>TELECAST HOVER</h4>
<div class="kontainer">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
<div class="e"></div>
<div class="f"></div>
</div>
@bshyong
bshyong / database.yml
Created July 15, 2013 13:52
Default Rails database.yml for sqlite3
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
@bshyong
bshyong / application.yml
Created July 15, 2013 14:21
Default application.yml file for storing credentials and API keys.
# Add account credentials and API keys here.
# See http://railsapps.github.io/rails-environment-variables.html
# This file should be listed in .gitignore to keep your settings secret!
# Each entry sets a local environment variable and overrides ENV variables in the Unix shell.
# For example, setting:
# GMAIL_USERNAME: Your_Gmail_Username
# makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
# Add application configuration variables here, as shown below.
#
SENDGRID_USERNAME: Your_Username
@bshyong
bshyong / gist:6257817
Last active December 21, 2015 05:38
Bash script to pull Heroku DB to local environment - note that this creates a manual backup via heroku pgbackups:capture
#!/bin/bash
# call command with bash pull_production_to_local
function LastBackupName () {
heroku pgbackups --app APPNAME | tail -n 1 | cut -d " " -f 1
}
heroku pgbackups:capture --expire --app APPNAME
new_backup=$(LastBackupName)
@bshyong
bshyong / python_bst.py
Last active March 11, 2021 23:09
Python BST implementation
class BSTnode(object):
"""
Representation of a node in a binary search tree.
Has a left child, right child, and key value, and stores its subtree size.
"""
def __init__(self, parent, t):
"""Create a new leaf with key t."""
self.key = t
self.parent = parent
self.left = None