Skip to content

Instantly share code, notes, and snippets.

View ajsharp's full-sized avatar

Alex Sharp ajsharp

View GitHub Profile
@ajsharp
ajsharp / fading_nav.js
Last active October 6, 2015 00:43
Fading navbar implementation on http://frothlogic.com
$(window).on('scroll', function() {
var scrollY = window.scrollY;
var $jumbotron = $('.jumbotron');
var $nav = $('nav:first');
var fullBlack = $jumbotron.height() - $jumbotron.position().top;
var blackNess = (scrollY / fullBlack);
$nav.css({'background-color' : 'rgba(0,0,0,'+blackNess+')'});
});
@ajsharp
ajsharp / heroku-env-to-opsworks
Created April 23, 2015 00:38
This handy little script makes it super easy to add all your heroku environment configuration to an AWS Opsworks app. Very handy if you're moving off Heroku and onto opsworks.
#!/usr/bin/env ruby
require 'json'
app_name = 'APP_NAME'
opsworks_app_id = 'APPID'
config = `heroku config -s --app #{app_name}`.strip
json = []
@ajsharp
ajsharp / migrate-route53-dns
Last active July 3, 2023 18:35
This script makes it very easy to migrate an entire DNS zone from one AWS Route53 zone to another. This script expects you to have downloaded the old zone file via the AWS CLI to a json file called DOMAIN.zone.json. It uses the AWS CLI to perform the request, so make sure that your credentials are properly configured.
#!/usr/bin/env ruby
require 'json'
# This is the json output of the old zone, fetched using the AWS CLI.
zone = JSON.parse(File.read('DOMAIN.zone.json'))['ResourceRecordSets']
new_zone_id = 'NEW_ZONE_ID'
# We don't want to migrate the SOA and NS records from the old zone.
@vgeshel
vgeshel / function.js
Last active March 6, 2025 13:44
AWS Lambda function for forwarding SNS notifications to Slack
console.log('Loading function');
const https = require('https');
const url = require('url');
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration
const slack_url = 'https://hooks.slack.com/services/...';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};
@GregBaugues
GregBaugues / token.rb
Last active March 28, 2025 10:16
Google API OAuth 2.0 refresh token (Ruby on Rails)
# The OAuth access token provided by the Google API expires in 60 minutes. After expiration,
# you must exchange a refresh token for a new access token. Unfortunately, the the Google API
# ruby gem does not include a method for refreshing access tokens.
# You can read up on how to refresh an access token here:
# https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
# This Token model implements that process. It's based off of a Token model that can be created
# by running:
# rails g model Token token:text refresh_token:string expires_at:datetime
//
// MKMapView+ZoomLevel.h
//
// Created by Daniel.Burke on 7/3/14 via Nikita Galayko @ StackOverflow
// Copyright (c) 2014 Forrent.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#define MERCATOR_RADIUS 85445659.44705395
#define MAX_GOOGLE_LEVELS 20
@ajsharp
ajsharp / email_example.rb
Last active August 29, 2015 14:01
This describes two potential API for running jobs in the future. One is a simple, abstract job, where the logic lives in your application, and is triggered via a webhook at the scheduled time. The other is a SMS notification that is due to fire at some point in the future.
# Often times we need to send emails on a delayed basis. We could make this really easy on the client
# side by automatically mounting an endpoint with rack middleware, and firing the mailer with the
# arguments supplied.
#
# Under the hood, this would use the same architecture as an abstract job, where a webhook is hit
# at the specified time, but by focusing on the email / action mailer use case the client doesn't need
# to write any boilerplate code.
Tick::EmailJob.create!(
:at => appointment.start_time - 1.hour,
:message => "Don't forget, your appointment starts in 1 hour!",
@jberkus
jberkus / gist:6b1bcaf7724dfc2a54f3
Last active July 31, 2025 20:15
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@mitchwongho
mitchwongho / Docker
Last active August 4, 2025 15:34
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash
{
"deploy": {
"discourse": {
"database": {
"adapter": "postgresql",
"host": "aaa.amazonaws.com",
"port": "5432",
"database": "bbb",
"pool": "5",
"username": "ccc",