Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Working from 🛰

Harry Moreno morenoh149

💭
Working from 🛰
View GitHub Profile
@morenoh149
morenoh149 / index.html
Created Jul 20, 2012
normal distribution generator (press F5)
View index.html
<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 Jul 20, 2012
transition d3js tutorial
View index.html
<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 Oct 14, 2012
History of Federal Individual Income Bottom and Top Bracket Rates
View data.csv
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 Oct 18, 2012
How do you write a ECDF function for an arbitrary dataset
View squareCDF.R
#!/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 Oct 19, 2012
determine avg hourly temperature of 3 airports via json query
View pricenomics.R
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)
View Balanced Parentheses Prompt
#
# 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 Dec 9, 2013
creating comments on posts. users have many posts. many users may comment on a post.
View comments_contorller.rb
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 Dec 17, 2013
fix n+1 query. User has many posts. I want to get 3 random posts from every user.
View users_controller.rb
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 Jan 26, 2014
Bash script to help create a bootable usb stick on OS X
View put_iso_on_usb.sh
#!/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 Jan 4, 2016
resize icon grunt task for mobile-chrom-apps
View gruntfile.js
// 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' }
},