Skip to content

Instantly share code, notes, and snippets.

View amitnarayanan's full-sized avatar

Amit Narayanan amitnarayanan

View GitHub Profile
@amitnarayanan
amitnarayanan / README.md
Created November 9, 2021 22:52
Python via Pyenv on Mac

Install XCode commandline tools

$ ./install_dev_tools.sh

Install homebrew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
'use strict';
console.log('Loading tax calculator function...');
exports.handler = (event, context, callback) => {
console.log('Received event: ', JSON.stringify(event, null, 2));
try {
let productPrice, taxRate, surchargeRate = null;
@amitnarayanan
amitnarayanan / StripedLock.java
Created March 5, 2016 18:24
A simple striped lock
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
/**
* Striped lock impl for when proper concurrency libs (like guava) can't be used, either due to
* dependency issues or other reasons.
*
* Returns (creates if not exists) a unique Lock for a given K
@amitnarayanan
amitnarayanan / attachment_processor.rb
Created April 16, 2015 00:06
Pseudo code for uploading attachments to AWS S3
# if there are attachments...
if @email.attachments.present?
# ...loop over each one...
@email.attachments.each do |attachment|
# ... and upload to storage provider
response = storage.put_object($BUCKET_NAME, # S3 bucket
attachment.original_filename, # filename
attachment, # the ActionDispatch::Http::UploadedFile object returned by Griddler
$OPTIONS # things like Content-Type headers, S3 acl go here
gem 'griddler'
gem 'griddler-mandrill'
config.action_controller.asset_host = 'https://YOURKEY.cloudfront.net'
# I don't want to manually start everything I need... so
#
# Two web processes
#
web1: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
web2: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
#
# Workers