Skip to content

Instantly share code, notes, and snippets.

View raorao's full-sized avatar

Srinivas Rao-Mouw raorao

  • San Francisco, CA
View GitHub Profile
repository available at: https://github.com/raorao/ar-student-schema
For this challenge, I created a simple Students table using AR migration, populated a student object with basic methods and validations.
@raorao
raorao / closures.js
Last active December 28, 2015 06:09
Here's my attempt at explaining closures in JavaScript.
// As I've been know to yell, JavaScript is a stupid language, and I don’t mean that as an insult.
// For example, where Ruby has 50-ish enumerable methods to iterate over collections,
// JS has, basically, two. But that’s okay! That just means you have to build any complicated
// logical structures yourself in JavaScript, which makes your code more transparent and flexible.
// One important structure you often find yourself building from scratch is private functionality
// in object oriented programming. JavaScript closures are one way to achieve that goal.
var counter = (function() {
var currentCount = 0;
return {
<html>
<head>
</head>
<body>
<script src="jquery.js" type=text/javascript></script>
<script type=text/javascript>
$(document).ready(function() {
addKISSmetricsToButtons();
<?php
function slowApiLookup() {
try {
$url = "http://slowapi.com/delay/5.0";
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlSession, CURLOPT_TIMEOUT,1);
$response = curl_exec($curlSession);
//JavaScript Promises! They are the next big thing in JavaScript, the coolest thing
//you've never heard about in the coolest language out there. And as of last year,
//They are supported by new builds of Chrome. It's only a matter of time until
//they're supported everywhere. So...what are they?
//Well, in essence, a Promise represents an asynchronous task. While the task is
//being completed, it is represented by a Promise object, and once completed it
//returns the value you expected. They are a tool to handle asynchronous functionality
//in JavaScript, as well as make your code more readable, extendable, and better at
//handling errors. So what do they look like? Well before we can do that, we need to
#HTTParty isn't broken! it deals with 304 errors as per RFC 2616,
#returning a response with headers but no body.
require 'httparty'
response = HTTParty.get("https://api.github.com/users/octocat", {
:headers => {"User-Agent" => "HTTParty"},
})
etag = response.headers["etag"]

Sampler

The challenge is to implement a program called "sample" that outputs a sorted list of random numbers to the console. Your program should be run like this:

ruby sample MEMBERS LIMIT

MEMBERS is the number of results you want the program to output, and LIMIT is the upper limit for the sample range. All results should be greater than or equal to 0 and less than LIMIT. Some examples:

BalanceValidator

The challenge is to write a function that evaluates whether an ordered list of edge characters — parentheses, brackets, or curly braces — is correctly balanced according to the following rules:

  1. Each opening character must be eventually followed by its corresponding closing character. (e.g. an opening parenthesis must be followed by a closing parenthesis, but not necessarily immediately.)

  2. The characters must be nested correctly, so that each pair of characters maintains a valid scope. (e.g. an opening bracket cannot be immediately followed by a closing curly brace.)

This challenge must be written in JavaScript. For ease of use, I suggest using node.

PacMan!

Given a map, your program should find the shortest path between PacMan and Food.

The map is defined as a two-dimensional array, with the following key:

  • 'o' = open space
  • 'w' = wall
  • 'F' = food
  • 'P' = PacMan
@raorao
raorao / witty_gem_name.rb
Created December 4, 2014 18:32
Google Docs ORM spec
# all permissions/setup are handled through the google docs interface. basically, this isn’t a DSL for google docs. figure that shit out yourself.
# all querying logic happens in ruby. find is provided for simplicity.
# no optimizing for speed. this is a google doc db after all.
# connections only occur when necessary. no preloading. avoid unncessary connections after first.
# configuration must be simple. and preferably self-contained within file.
#not tied to language. would be cool to do this as a front-end JS library too.
class User < APIModel
def self.configure
@SPREADSHEET_URL = ‘someurl’