Skip to content

Instantly share code, notes, and snippets.

View morenoh149's full-sized avatar
💭
Working from 🛰

Harry Moreno morenoh149

💭
Working from 🛰
View GitHub Profile
@morenoh149
morenoh149 / index.html
Created July 20, 2012 06:31
normal distribution generator (press F5)
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
@morenoh149
morenoh149 / index.html
Created July 20, 2012 07:50
transition d3js tutorial
<meta charset="utf-8">
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
</head>
<body>
<button class="btn btn-mini" id="button">Transition</button>
<script type="text/javascript">
var svg = d3.select("body")
.append("svg")
@morenoh149
morenoh149 / data.csv
Created October 14, 2012 07:34
History of Federal Individual Income Bottom and Top Bracket Rates
year Bottom bracket Taxable Income upto Top bracket Taxable Income over Party
1913 1 20000 7 500000 D
1914 1 20000 7 500000 D
1915 1 20000 7 500000 D
1916 2 20000 15 2000000 D
1917 2 2000 67 2000000 D
1918 6 4000 77 1000000 D
1919 4 4000 73 1000000 D
1920 4 4000 73 1000000 D
1921 4 4000 73 1000000 R
@morenoh149
morenoh149 / squareCDF.R
Created October 18, 2012 21:41
How do you write a ECDF function for an arbitrary dataset
#!/usr/bin/env/Rscript
squareCDF <- function(n=100){
# create random data
user_id <- seq(1,n)
payment_id <- seq(101,n+100)
payment_amount <- rnorm(n, mean= 100, sd=50)
is_card_present <- sample(0:1, n, replace=T)
data <- data.frame(user_id, payment_id, payment_amount, is_card_present)
# calculate ECDF
@morenoh149
morenoh149 / pricenomics.R
Created October 19, 2012 01:34
determine avg hourly temperature of 3 airports via json query
library('RJSONIO')
library('plyr')
# get data
source <- "http://dl.dropbox.com/u/274/readings_formatted.json"
data_raw <- fromJSON(source)
# format data into dataframe
data <- do.call('rbind.fill', lapply(data_raw, as.data.frame))
data$timestamp <- as.POSIXlt(data$timestamp)
#
# write a function that takes a string of text and returns true if
# the parentheses, brackets, and braces are balanced and false otherwise.
#
# Example:
# balanceParens('[](){}'); // true
# balanceParens('[({})]'); // true
# balanceParens('[(]{)}'); // false
#
# Step 3:
@morenoh149
morenoh149 / comments_contorller.rb
Created December 9, 2013 00:20
creating comments on posts. users have many posts. many users may comment on a post.
class CommentsController < ApplicationController
before_filter :authenticate_user!
def index
@comments = Post.includes(:comments).find(params[:post_id])
end
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(comment_params)
@morenoh149
morenoh149 / users_controller.rb
Created December 17, 2013 22:50
fix n+1 query. User has many posts. I want to get 3 random posts from every user.
def index
users = User.includes(:posts)
users.each do |u|
puts u.posts.limit(3)
end
@comment = Comment.new
end
@morenoh149
morenoh149 / put_iso_on_usb.sh
Created January 26, 2014 23:15
Bash script to help create a bootable usb stick on OS X
#!/bin/bash
HELP_STR="please provide location of .iso"
if [ "$#" -lt 1 ]; then
echo $HELP_STR
else
echo "`diskutil list`"
echo "==============="
echo "enter disk to eject"
echo -e ">> \c"
read word
@morenoh149
morenoh149 / gruntfile.js
Last active January 4, 2016 20:59
resize icon grunt task for mobile-chrom-apps
// for https://github.com/MobileChromeApps/mobile-chrome-apps/blob/master/docs/NextSteps.md
module.exports = function(grunt) {
grunt.initConfig({
image_resize: {
options: { overwrite: true, upscale: true, crop: true },
icon_16: {
options: { width: 16, height: 16 },
files: { 'www/assets/icon16.png':'www/assets/icon.png' }
},