Skip to content

Instantly share code, notes, and snippets.

View hrishimittal's full-sized avatar

Hrishi Mittal hrishimittal

View GitHub Profile
@hrishimittal
hrishimittal / Postgres
Last active January 6, 2017 15:11
Postgres
#Dump database
pg_dump -Fc -f filename.pgdump database_name
#Restore db from dump
dropdb database_name && createdb database_name
pg_restore -n public -x -d database_name -j 2 -Fc filename.pgdump > /dev/null
psql:
#create role
@hrishimittal
hrishimittal / convenience.rb
Last active August 29, 2015 14:15
Ruby convenience methods
#Given an array, get counts of occurences for each element
#H/T http://jerodsanto.net/2013/10/ruby-quick-tip-easily-count-occurrences-of-array-elements/
def count_array_element_occurences(arr)
arr.each_with_object(Hash.new(0)) { |word,counts| counts[word] += 1 }
end
#Given a hash, convert it to an HTML table
def hash_to_table(h)
t = "<table><thead>"
if h.present?
@hrishimittal
hrishimittal / Equity.md
Last active March 1, 2024 21:13 — forked from isaacsanders/Equity.md
Joel Spolsky's Totally Fair Method to Divide Up The Ownership of Any Startup

This is a post by Joel Spolsky, originally posted on answers.onstartups.com in response to a question. You can find a copy here.

Forming a new software startup, how do I allocate ownership fairly?

This is such a common question here and elsewhere that I will attempt to write the world's most canonical answer to this question. Hopefully in the future when someone on answers.onstartups asks how to split up the ownership of their new company, you can simply point to this answer.

The most important principle: Fairness, and the perception of fairness, is much more valuable than owning a large stake. Almost everything that can go wrong in a startup will go wrong, and one of the biggest things that can go wrong is huge, angry, shouting matches between the founders as to who worked harder, who owns more, whose idea

Keybase proof

I hereby claim:

  • I am hrishimittal on github.
  • I am hrishio (https://keybase.io/hrishio) on keybase.
  • I have a public key whose fingerprint is 8A14 B5B8 2EFD B349 E1F7 F38A C84E 006F 6C18 3EED

To claim this, I am signing this object:

@hrishimittal
hrishimittal / macbook_setup.md
Last active September 25, 2020 09:53
Setting up a new MacBook for Ruby on Rails web development
  1. Install Google Chrome
  2. Install Karabiner-Elements and map fn key to ctrl - https://github.com/tekezo/Karabiner-Elements
  3. Install Homebrew - http://brew.sh/
  4. Install GnuPG - brew install gnupg2
  5. Generate SSH key - ssh-keygen -t rsa -b 4096 -C "hrishimittal@gmail.com"
  6. Install rvm - http://rvm.io/
  7. Install ruby - rvm install 2.4.0 (or whatever the latest version is)
  8. Install Postgres.app - https://postgresapp.com/ Add psql to path - /Applications/Postgres.app/Contents/Versions/latest/bin/psql
  9. Git - brew install git
@hrishimittal
hrishimittal / importxml.md
Last active February 9, 2017 10:14
ImportXml function for scraping web data into Google Sheets

#ImportXml function for scraping web data into Google Sheets

Note: All URLs must include the protocol - http:// or https://

Page Title

=IMPORTXML(URL, "//title")

Page Description

@hrishimittal
hrishimittal / index.html.erb
Last active February 26, 2017 22:19
shopping list items
<%= react_component('Lists', lists: @lists) %>
@hrishimittal
hrishimittal / FormErrors.js
Last active March 12, 2017 17:53
react form validation
import React from 'react';
export const FormErrors = ({formErrors}) =>
<div className='formErrors'>
{Object.keys(formErrors).map((fieldName, i) => {
if(formErrors[fieldName].length > 0){
return (
<p key={i}>{fieldName} {formErrors[fieldName]}</p>
)
} else {

[title] How to use React with a Rails 5 API app - A hands-on tutorial

[intro]

  • React and Rails make a great combination
  • In this hands-on tutorial, I'll show you how to build a complete React app that works with a Rails 5 API
  • You need to be comfortable with Rails but don't need to be a JavaScript or React expert
  • What we're going to build - an Idea board!
  • Outline of the steps we'll take to build this app
#Put this in application_controller.rb to trace all redirects
def redirect_to(options = {}, response_status = {})
puts("Redirected by #{caller(1).first rescue "unknown"}")
super(options, response_status)
end
#Put this in application_controller.rb to trace all redirects