Skip to content

Instantly share code, notes, and snippets.

View dahal's full-sized avatar
🌟
captableinc/captable

Puru Dahal dahal

🌟
captableinc/captable
View GitHub Profile
@dahal
dahal / Procfile
Created October 9, 2017 21:17 — forked from arches/Procfile
A little hack to restart Heroku web dynos when they hit 1000MB of memory
monitor: bundle exec ruby monitor.rb
@dahal
dahal / instant_articles.rb
Created August 30, 2017 17:47 — forked from kkyouhei/instant_articles.rb
Instant Articles API for Ruby
require 'net/http'
page_id = "your page id"
access_token = "your access token"
html_source = "your html content"
uri = URI.parse("https://graph.facebook.com/v2.6/#{page_id}/instant_articles")
request = Net::HTTP::Post.new(uri.path)
request.set_form_data({
access_token: access_token,
@dahal
dahal / threeio.rb
Created August 16, 2017 04:26 — forked from tlehman/threeio.rb
List all available three-character .io domain names (depends on colorize)
require 'net/http'
require 'colorize'
# find all available three-letter .io domains
alph = ('a'..'z')
# generate all three-character strings
threes = alph.map { |a| alph.map { |b| alph.map { |c| "#{a}#{b}#{c}" } } }.flatten
def io_available?(tld)
url = URI.parse("http://www.nic.io/cgi-bin/whois?query=#{tld}.io")
@dahal
dahal / registrations_controller.rb
Created December 13, 2016 00:40 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@dahal
dahal / lambda-dynamo
Created May 4, 2016 04:32 — forked from markusklems/lambda-dynamo
Short aws lambda sample program that puts an item into dynamodb
// create an IAM Lambda role with access to dynamodb
// Launch Lambda in the same region as your dynamodb region
// (here: us-east-1)
// dynamodb table with hash key = user and range key = datetime
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function(event, context) {

Deploy Rails 4 app with Dokku on DigitalOcean

Install dokku

First create a Ubuntu 13.04 x64 droplet on DigitalOcean Control Panel

Then ssh with root account, run this in termianl:

$ wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash
@dahal
dahal / PostalAddress.rb
Last active March 21, 2016 23:24 — forked from colinyoung/PostalAddress.rb
Parses a postal address into its components. (limited) i18n support and other features. inspired by this forrst post: http://forr.st/~zDa
#
# Most of the regexes here are from http://twitter.com/schuyler.
# They were posted on Forrst (http://forr.st/~zDa) as a public post,
# so I reworked them into a full class.
#
# Added:
# => (limited) international support -- should handle US/Canada and most of western europe
# => added :receipient, :postcode, and :country fields
# => state/province detection built-in
@dahal
dahal / sitemap.xml.erb
Last active August 29, 2015 14:27 — forked from ls-lukebowerman/sitemap.xml.erb
Sitemap (sitemaps.org) generator for Middleman
<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% pages.each do |p| %>
<url>
<loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
<priority>0.7</priority>
</url>
<% end %>
</urlset>
@dahal
dahal / landing-pages.md
Last active August 29, 2015 14:26 — forked from revolunet/landing-pages.md
Beautiful SAAS landing pages
module.exports = (grunt) ->
# configuration
grunt.initConfig
# grunt sass
sass:
compile:
options:
style: 'expanded'