Skip to content

Instantly share code, notes, and snippets.

@bknarendra
bknarendra / flickr_download_album.rb
Created September 12, 2016 20:39
Download images from shared Flickr album 1 by 1. It has the ability to resume downloads if it is interrupted. Also you can download images in different size options
require 'mechanize'
require 'json'
ALBUM_URL = ARGV[0]
ALBUM_NAME = ARGV[1]
SIZE_TO_DOWNLOAD = ARGV[2]
if !ALBUM_URL || !ALBUM_NAME
puts "Usage: ruby #{__FILE__} <album_url> <album_name> [size_to_download_image]"
puts "size_to_download_image default 'o' which is original. Other available options in descending order of size k, h, l, c, m etc."
exit!
@bknarendra
bknarendra / gmail_notifier.rb
Created January 5, 2014 13:06
Gmail Notifier for Mac OSX
['gmail','terminal-notifier'].each {|x| require x}
username = 'emailid'
password = %x(security 2>&1 find-internet-password -ga #{username} | grep password | cut -d '"' -f2).strip
gmail = Gmail.new(username, password)
puts "logged in to gmail"
path = "#{ENV['HOME']}/.gmail_notifier_last_running_time"
last_running_time = File.exists?(path) ? Time.now.to_i : File.read(path).strip.to_i
flag, idx = 0, 0
search_queries = [[:subject, "sweets"],[:subject, "chocolates"],[:body, "sweets"],[:body, "chocolates"]]
while flag == 0
@bknarendra
bknarendra / gist:6496065
Created September 9, 2013 14:07
Download all railscasts videos
require 'mechanize'
a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari'}
url=your_subscription_url
doc=nil
a.get url
for i in 1..420
begin
url="http://railscasts.com/episodes/#{i}"
a.get url do |page|
doc=page.parser
@bknarendra
bknarendra / keyvaluedb.rb
Created December 26, 2012 10:15
A simple No-SQL key-value db using self-modifying ruby script: An interesting application of Ruby's Reflection API
hash={"1"=>"Narendra", "2"=>"Mangesh", "3"=>"Viru", "4"=>"Virendra", "5"=>"Genh"}
z=[]
err_msg="ruby #{__FILE__} <GET/SET> <key_to_search/key_to_set> <not_required/value_to_set>"
if ARGV.length<2 && (ARGV[0]!="GET" || ARGV[0]!="SET")
puts err_msg
exit
end
if ARGV[0]=="SET" && ARGV.length!=3
puts err_msg
exit
@bknarendra
bknarendra / gist:3072515
Created July 8, 2012 19:44
Find a word in 2D matrix
import java.util.*;
import java.io.*;
public class Main{
public static int flag=0,m,n,dx[]={0,0,1,-1};
public static int dy[]={1,-1,0,0};
public static char wrd[];
static class S{char a;int p,x,y;
S(){}
S(char b,int pos,int c,int d){a=b;p=pos;x=c;y=d;}
}
@bknarendra
bknarendra / gist:3072504
Created July 8, 2012 19:42
Find a word in 2D matrix
import java.util.*;
import java.io.*;
public class Main{
public static int flag=0,m,n,dx[]={0,0,1,-1};
public static int dy[]={1,-1,0,0};
public static char wrd[];
static class S{char a;int p,x,y;
S(){}
S(char b,int pos,int c,int d){a=b;p=pos;x=c;y=d;}
}
class Node{
public char d;public boolean e;
public LinkedList<Node>c;
public Node(){}
public Node(char a){d=a;e=Boolean.FALSE;c=new LinkedList<Node>();}
public Node sub(char a){
int i;
if(c.isEmpty()) return null;
for(i=0;i<c.size();i++)
if(c.get(i).d==a) return c.get(i);
@bknarendra
bknarendra / gist:3072072
Created July 8, 2012 18:01
Levenshtein distance
import java.io.*;
import java.util.*;
public class levenshtein_distance{
public static HashSet[]h=new HashSet[25];
public static Stack<String>st=new Stack<String>();
public static HashSet<String>fnl=new HashSet<String>();
public static void main(String args[]) throws Exception{
long aa=System.currentTimeMillis();
InputReader sc=new InputReader(new FileInputStream("in.txt"));
int i,j;
import java.util.*;
import java.io.*;
public class AddAGram{
public static Vector<String>dic[];
public static Stack<String>s;
public static HashSet<String>vis=new HashSet<String>();
public static boolean check(char []l,char []s){
int i,j,len=l.length;
for(i=0;i<s.length;i++)
for(j=0;j<l.length;j++)
@bknarendra
bknarendra / gist:2692525
Created May 14, 2012 07:47
CoderCharts:Crosswords
import java.util.*;
import java.io.*;
class Node {
char content;
boolean marker;
Collection<Node> child;
public Node(char c){
child = new LinkedList<Node>();
marker = false;
content = c;