Skip to content

Instantly share code, notes, and snippets.

View schowdhury's full-sized avatar

Sameer Chowdhury schowdhury

View GitHub Profile
@schowdhury
schowdhury / get_s3_file.sh
Created April 26, 2018 03:05 — forked from davidejones/get_s3_file.sh
curl get file from private s3 with iam role
#!/bin/bash
instance_profile=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
aws_access_key_id=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep AccessKeyId | cut -d':' -f2 | sed 's/[^0-9A-Z]*//g'`
aws_secret_access_key=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep SecretAccessKey | cut -d':' -f2 | sed 's/[^0-9A-Za-z/+=]*//g'`
token=`curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | sed -n '/Token/{p;}' | cut -f4 -d'"'`
file="somefile.deb"
bucket="some-bucket-of-mine"
date="`date +'%a, %d %b %Y %H:%M:%S %z'`"
@schowdhury
schowdhury / nginx.conf
Last active August 29, 2015 14:27 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your location block(s):
#
# include cors_support;
#
# A limitation to this method is that Nginx doesn't currently send headers
var ngAppElem = angular.element(document.querySelector('[ng-app]') || document);
window.injector = ngAppElem.injector();
window.inject = injector.invoke;
window.$rootScope = ngAppElem.scope();
// getService('auth') will create a variable `auth` assigned to the service `auth`.
var getService = function getService(serviceName) {
inject([serviceName, function (s) {window[serviceName] = s;}]);
};
If your introduction to object-oriented programming was like mine, somewhere early on day 1 you learned about “message passing.” You were told that doing something like
account.deposit(50)
meant that you were sending the deposit message to the account object. Of course, if you were learning about a statically typed language, you soon figured out that account.deposit(50) was synonymous with calling the deposit method on the account object. The whole static typing system was there to make sure that the deposit method was there and was called. So by the end of day 1 of object-oriented programming, we all stopped talking about passing messages and started talking about calling methods.
The concept of message passing would make more sense if we could say account.deposit(50), and the BankAccount class was then free to do something else with the message besides simply calling the deposit method. Perhaps the BankAccount class could call some method other than deposit, or perhaps it could decide to do nothing. I
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')

Nginx + Unicorn for Rails on Rackhub

Description:

This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.

Installation:

Please make sure that your Gemfile in your rails application includes unicorn.

#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "someone@somewhere.com"
@from = "must_be_same_as_smpt_account_login@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
@schowdhury
schowdhury / gist:2638887
Created May 8, 2012 20:02
log rotation
-----------------------------
logrotate
-----------------------------
modify /etc/logrotate.d/apache2 with content
#####
/var/log/apache2/*.log {
daily
missingok
rotate 20
compress
@schowdhury
schowdhury / gist:1690705
Created January 27, 2012 20:19
jquery autocomplete return id instead of text
var select_function = function(event, ui) {
if ($(this).data("event-name") == undefined) {
$(this).data("event-name", $(this).attr("name"));
}
if(ui.item) {
var hidden_location;
// currently only care if there's a child, not checking the childs type
if ($(this).children().size() == 0 ) {
hidden_location = $('<input type=hidden></input>')
hidden_location.attr("name", $(this).data("event-name"))