Skip to content

Instantly share code, notes, and snippets.

View jiren's full-sized avatar

Jiren Patel jiren

View GitHub Profile
@jiren
jiren / gc-storage-upload.js
Created August 14, 2019 07:58
Google cloud storage upload issue
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 November 1, 2013 09:42
Elasticsearch: Remove stem words from index data using snowball analyzer.
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 October 20, 2013 19:02
Insearch private search and doc save api
source 'https://rubygems.org'
gem 'faraday'
gem 'json'
@jiren
jiren / bson_ruby_oid_fix.rb
Last active December 24, 2015 23:39
bson_ruby: Temporary patch for generating object_id in ascending order.
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 September 20, 2012 07:56
Mongodb collection copier using moped gem
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 September 4, 2012 10:07 — forked from mislav/geoip_service.rb
Simple GeoIP service class using freegeoip.net and Faraday
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 March 13, 2012 11:45
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
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 January 20, 2011 14:57
This generates 2 css files - sprite image and a css along with a datauri css.
#! /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: