Skip to content

Instantly share code, notes, and snippets.

@rkjha
rkjha / my_blog.rb
Last active Jun 8, 2020
Simple use of Dalli gem to implement caching using memcached in a Sinatra Application.
View my_blog.rb
require 'rubygems'
require 'sinatra/base'
require 'sinatra/content_for'
require 'dalli'
class MyBlog < Sinatra::Base
helpers Sinatra::ContentFor
set :dc, Dalli::Client.new('localhost:11211')
get '/articles/:id' do
@rkjha
rkjha / ad_unit_code.html
Created Jul 26, 2019
that dfpad unit for Amazon UAM. Nothing special for UAM - just your plain old dfp unit.
View ad_unit_code.html
<!-- /dfp_account_id/ad_unit_1 -->
<div id='div-gpt-ad-xxxxxxxxxx-0'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxxxxxxxx-0'); });
</script>
</div>
@rkjha
rkjha / amazon_uam_sample_config.js
Last active Jul 26, 2019
amazon_uam_sample_config for header.
View amazon_uam_sample_config.js
// Load APS library
!function(a9,a,p,s,t,A,g){if(a[a9])return;function q(c,r){a[a9]._Q.push([c,r])}a[a9]={init:function(){q("i",arguments)},fetchBids:function(){q("f",arguments)},setDisplayBids:function(){},targetingKeys:function(){return[]},_Q:[]};A=p.createElement(s);A.async=!0;A.src=t;g=p.getElementsByTagName(s)[0];g.parentNode.insertBefore(A,g)}("apstag",window,document,"script","//c.amazon-adsystem.com/aax2/apstag.js");
apstag.init({
pubID: 'pub_id_amazon_uam',
adServer: 'googletag',
simplerGPT: true
});
var googletag = googletag || {};
@rkjha
rkjha / nginx-passenger-ssl.conf
Last active Mar 25, 2021
Nginx/Passenger config when using SSL with a Ruby/Rails Application.
View nginx-passenger-ssl.conf
# for redirecting hhtp traffic to https version of the site
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
# for redirecting to non-www version of the site
server {
listen 80;
@rkjha
rkjha / example.conf
Last active Aug 29, 2015
A sample nginx config for static websites.
View example.conf
server {
listen 80;
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen 80;
server_name example.com;
@rkjha
rkjha / post-receive
Created Jul 12, 2015
Git post-receive hook for deployment
View post-receive
#!/bin/sh
echo 'Deploying to the server............'
GIT_WORK_TREE=/home/example_user/example.com git checkout -f
echo '..............................Done.'
@rkjha
rkjha / basic_server_setup.sh
Last active Sep 25, 2015
Basic server setup for deploying static websites
View basic_server_setup.sh
## Basic VPS Setup for deploying static sites
## Server OS : Ubuntu 14.04 LTS 64 bit
## Author: Ramesh Jha (ramesh[at]rameshjha.com),(http://blog.sudobits.com)
## License: MIT
#### SSH into the server `ssh root@IP_ADDRESS`
### 1. Update system packages
apt-get -y update
apt-get -y upgrade
@rkjha
rkjha / skeleton-form.html
Created May 13, 2015
A sample form when using skeleton css.
View skeleton-form.html
<form id="loginForm" action="/whatever" method="post">
<div class="row">
<div class="seven columns">
<label for="email">Email Address</label>
<input type="text" name="email" id="emailField" placeholder="name@example.com" required/>
<label for="password">Password</label>
<input type="password" name="password" id="passwordField" required/>
<button type="submit" class="button-primary">Sign In</button>
@rkjha
rkjha / skeleton-grid.html
Created May 13, 2015
A sample skeleton grid.
View skeleton-grid.html
<div class="container">
<div class="row">
<div class="eight columns">Main</div>
<div class="four columns">Sidebar</div>
</div>
</div>
@rkjha
rkjha / example.com.conf
Created Nov 12, 2014
A simple nginx config for sinatra app [with passenger app server]
View example.com.conf
server {
listen 80;
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen 80;
server_name example.com;