Skip to content

Instantly share code, notes, and snippets.

Avatar

Jiren Patel jiren

View GitHub Profile
@jiren
jiren / gc-storage-upload.js
Created Aug 14, 2019
Google cloud storage upload issue
View gc-storage-upload.js
const {Storage} = require('@google-cloud/storage')
const storage = new Storage();
const bucket = storage.bucket('fe-store');
async function upload() {
const largeCustomMeta = () => {
let str = '';
for (let i = 0; i < 2.1e6; i++) {
str += 'a';
}
@jiren
jiren / stemword.rb
Created Nov 1, 2013
Elasticsearch: Remove stem words from index data using snowball analyzer.
View stemword.rb
require 'elasticsearch'
require 'pp'
index_name = 'test'
@client = Elasticsearch::Client.new log: true
@client.indices.delete(index: index_name) rescue ''
@client.indices.create index: index_name,
body: {
settings: {
analysis: {
@jiren
jiren / Gemfile
Created Oct 20, 2013
Insearch private search and doc save api
View Gemfile
source 'https://rubygems.org'
gem 'faraday'
gem 'json'
@jiren
jiren / bson_ruby_oid_fix.rb
Last active Dec 24, 2015
bson_ruby: Temporary patch for generating object_id in ascending order.
View bson_ruby_oid_fix.rb
require 'bson'
# Undefine 'next' method which is define by c ext.
BSON::ObjectId::Generator.send :undef_method, :next
# Redefine next method.
module BSON
class ObjectId
class Generator
def next(time = nil)
@jiren
jiren / MongoCopier.rb
Created Sep 20, 2012
Mongodb collection copier using moped gem
View MongoCopier.rb
require 'rubygems'
require 'moped'
class MongoCopier
attr_accessor :source_addr, :dest_addr, :db_name
attr_reader :source_session, :dest_session
def initialize(db_name, addrs = {})
@source_addr = addrs[:source] || 'localhost:27017'
@jiren
jiren / geoip_service.rb
Created Sep 4, 2012 — forked from mislav/geoip_service.rb
Simple GeoIP service class using freegeoip.net and Faraday
View geoip_service.rb
require 'faraday_middleware'
require 'hashie/mash'
# Public: GeoIP service using freegeoip.net
#
# See https://github.com/fiorix/freegeoip#readme
#
# Examples
#
# res = GeoipService.new.call '173.194.64.19'
@jiren
jiren / Gemfile
Created Mar 13, 2012
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
View Gemfile
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@jiren
jiren / sprite_datauri_writer.rb
Created Jan 20, 2011
This generates 2 css files - sprite image and a css along with a datauri css.
View sprite_datauri_writer.rb
#! /usr/local/bin/ruby -w
# This simple program takes a bunch of images and creates a sprite image along with the corrosponding
# css. It also generates the datauri css. So, we can serve performance optimized CSS depending on the
# Browsers.
#
# Browsers which do not support datauri, like IE7 and below get the sprite image and the sprite css.
# Browsers which support datauri, get the datauri.css
#
# Usage: