Skip to content

Instantly share code, notes, and snippets.

@sanjeev2838
sanjeev2838 / gist:5221497
Created March 22, 2013 14:04
programming ruby book ----html parsing example
#def unescapeHTML(string)
# str = string.dup
# str.gsub!(/&(.*?);/n) {
# match = $1.dup
# case match
# when /\Aamp\z/ni then '&'
# when /\Aquot\z/ni then '"'
# when /\Agt\z/ni then '>'
# when /\Alt\z/ni then '<'
# when /\A#(\d+)\z/n then Integer($1).chr
@sanjeev2838
sanjeev2838 / gist:5221501
Created March 22, 2013 14:05
max sum project euler :---
#array = [ [3],
# [7 ,4],
# [2, 4, 6],
# [8, 5, 9, 3]
# ]
array =[[75],
[95,64],
[17,47,82],
[18,35,87,10],
[20,04,82,47,65],
@sanjeev2838
sanjeev2838 / gist:5221516
Created March 22, 2013 14:07
git profiling code
require 'profile'
count = 0
words = File.read("/usr/share/dict/words")
word12 = words.scan(/^............\n/)
puts word12.count
----------------------------------------------
require 'profile'
count = 0
@sanjeev2838
sanjeev2838 / gist:7f13e52345407622db18
Last active August 29, 2015 14:11
Elance project of scraping
require 'rubygems'
require 'mechanize'
require 'httparty'
options = {
body: {
IdNo: '02401C0123442014'
}
}
response = HTTParty.post('http://courtnic.nic.in/DDC_TisHazari/detail.asp', options)
@sanjeev2838
sanjeev2838 / yelp_scraping.rb
Created December 24, 2014 11:20
scraping example :-
require 'yelp'
require 'csv'
require 'nokogiri'
require 'open-uri'
require 'mechanize'
names = []
csv_file = File.open('/home/pardeep/Desktop/web scrapper/bakery/coffee_script/coffee_names.csv').read
CSV.parse(csv_file, :headers => true).each{|ob| names << ob[0]}
names = names.uniq
@sanjeev2838
sanjeev2838 / gist:ee65d1543716cf1c0e14
Created October 8, 2015 15:08
Ruby AES Encryption using OpenSSL
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
@sanjeev2838
sanjeev2838 / .gitconfig
Created July 11, 2016 11:46 — forked from robmiller/.gitconfig
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"
@sanjeev2838
sanjeev2838 / gist:c32fd23f7ba5bdf4a17a912f51bca26f
Created January 9, 2017 16:59
week day with date for Journal entry
require 'date'
def week_dates( week_num )
year = Time.now.year
week_start = Date.commercial( year, week_num, 1 )
week_end = Date.commercial( year, week_num, 7 )
(week_start..(week_end - 2)).each do |date|
puts date.strftime('%d-%m-%Y (%A)')
puts "\n---- Things to do ----\n\n\n"
str = <<-EOF
@sanjeev2838
sanjeev2838 / RubyMine OSX memory options
Created April 5, 2017 14:31
RubyMine memory options - increase heap size
https://asciinema.org/a/c61t971nzlckj0xo86ienfvgt
cp /Applications/RubyMine.app/Contents/bin/rubymine.vmoptions ~/Library/Preferences/RubyMine70/.
vi ~/Library/Preferences/RubyMine70/rubymine.vmoptions
require 'open-uri'
require 'nokogiri'
require 'fileutils'
lesson_url = ARGV.first
dir_chapter_name = lesson_url.split('/')[4]
lesson_url_id = lesson_url.split('/')[5]
def get_image_urls(url)
urls = []