Skip to content

Instantly share code, notes, and snippets.

View pamio's full-sized avatar

Pramod Solanky pamio

View GitHub Profile
input = {"Root"=>[{"1"=>[{"4"=>"leaf4", "5"=>"leaf5"}]}, {"2"=>[{"6"=>"leaf6", "7"=>"leaf7"}]}]}
def traverse(path = "")
self.each do|key, value|
if value.is_a?(Hash)
path += "#{key}=>"
value.traverse(path)
else
if value.is_a?(Array)
path += "#{key}=>"
REGISTER contrib/piggybank/java/piggybank.jar
DEFINE SUBSTRING org.apache.pig.piggybank.evaluation.string.SUBSTRING();
A = load 'gutenberg/sample.txt';
C = foreach A generate SUBSTRING((chararray)$0, 0, 5);
dump C;
A = load '/tmp/alice.txt';
B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word;
C = filter B by word matches '\\w+';
D = group C by word;
E = foreach D generate COUNT(C), group;
store E into '/tmp/alice_wordcount';
# CLOSURES IN RUBY     Paul Cantrell    http://innig.net
# Email: username "cantrell", domain name "pobox.com"
 
# I recommend executing this file, then reading it alongside its output.
#
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments,
# then trying to guess the output of the code!
 
# A closure is a block of code which meets three criteria:
#
@pamio
pamio / credit_card.rb
Created November 14, 2014 11:35
Credit Card Verification
class CreditCard
require 'date'
SUPPORTED_CARD_BRANDS = {
:MASTERCARD => "mastercard",
:AMEX => "american_express",
:DINNERS => "diners_club",
:DISCOVER => "discover",
:MAESTRO => "maestro",
:VISA => "visa",
2010-03-12
/*
JavaScript Module Pattern: In-Depth
The module pattern is a common JavaScript coding pattern. It’s generally well understood, but there are a number of advanced uses that have not gotten a lot of attention. In this article, I’ll review the basics and cover some truly remarkable advanced topics, including one which I think is original.
The Basics
We’ll start out with a simple overview of the module pattern, which has been well-known since Eric Miraglia (of YUI) first blogged about it three years ago. If you’re already familiar with the module pattern, feel free to skip ahead to “Advanced Patterns”.
@pamio
pamio / Gemfile
Last active August 29, 2015 14:24 — forked from cblunt/Gemfile
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
@pamio
pamio / nginx.conf
Last active August 29, 2015 14:27 — forked from calebwoods/nginx.conf
Sample Nginx config for deployment of Angular.js app
server { listen 80;
server_name example.com;
access_log /var/log/example.com/nginx.access.log;
error_log /var/log/example.com/nginx.error.log;
root /var/www/apps/example.com/public;
charset utf-8;
location / {
rewrite ^ https://$host$request_uri? permanent;
}
@pamio
pamio / assets.rake
Created September 23, 2015 12:49 — forked from melnikaite/assets.rake
# lib/capistrano/tasks/assets.rake
Rake::Task['deploy:assets:precompile'].clear
namespace :deploy do
namespace :assets do
desc 'Precompile assets locally and then rsync to remote servers'
task :precompile do
local_manifest_path = %x{ls public/assets/manifest*}.strip
# First configure your models to use Amazon s3 as storage option and setup the associated S3 config.
# Then add the classes your want to migrate in the klasses array below.
# Then run rake paperclip_migration:migrate_to_s3
# Should work but this is untested and may need some tweaking - but it did the job for me.
namespace :paperclip_migration do
desc "migrate files from filesystem to s3"
task :migrate_to_s3 => :environment do
klasses = [:product] # Replace with your real model names. If anyone wants to this could be picked up from args or from configuration.
klasses.each do |klass_key|