Skip to content

Instantly share code, notes, and snippets.

View dhruvasagar's full-sized avatar

Dhruva Sagar dhruvasagar

View GitHub Profile
#!/usr/bin/env ruby
require 'uri'
require 'json'
require 'net/http'
if ARGV.length > 0
query = ARGV[0]
else
print 'Input word: '
#!/usr/bin/env ruby
def fizz(num)
num % 3 == 0 ? "Fizz" : nil
end
def buzz(num)
num % 5 == 0 ? "Buzz" : nil
end
{
"customer_name": "Girish ",
"customer_phone_number": "8345657321",
"amount": 199,
"placement_date": "16/06/2016",
"line_items": [
{
"variant_sku": "TIWD2571_M",
"quantity": 1,
"lmdn_enabled": true,
nnoremap g> <ESC>vap:Twrite bottom-right<CR>
xnoremap g> :Twrite bottom-right<CR>
# Why is this change necessary ?
# How does it address the issue ?
# What side effects does this change have ?
# References
@dhruvasagar
dhruvasagar / WebRTC Outline.md
Created October 13, 2016 04:28
WebRTC Outline
  • Introduction to WebRTC
  • Why WebRTC ?
  • WebRTC underpinnings : Signaling, STUN, TURN
  • Open Source Libraries & Tools available
  • Building your own Signaling Server
  • Demo
alert('test');
if exists('g:loaded_pairify')
finish
endif
let g:loaded_pairify = 1
let g:pairs = {
\ "left": {
\ "[": "]",
\ "(": ")",
\ "{": "}",
@dhruvasagar
dhruvasagar / add_missing_master_variants.rb
Last active June 20, 2018 19:20
Script to add master variants for spree_products that are missing them
puts "Rails environment is #{Rails.env}"
products_without_master = Spree::Product.joins('left outer join spree_variants sv on sv.product_id = spree_products.id and sv.is_master = 1').where('sv.id is null').all
ids_without_master = products_without_master.map(&:id)
puts "Spree products without master variants are #{ids_without_master.count} in number and have ids #{ids_without_master}"
updated_at_values = products_without_master.map(&:updated_at)
ActiveRecord::Base.transaction do
puts "Creating missing master variants inside a transaction..."
@dhruvasagar
dhruvasagar / damerau_levenshtein_distance.rb
Last active March 3, 2019 21:34 — forked from dimus/damerau_levenshtein distance for ruby
Damerau-Levenshtein distance for ruby in C
#!/usr/bin/env ruby1.9
# encoding: UTF-8
require 'rubygems'
require 'inline'
require 'time'
class DamerauLevenshtein
def distance(str1, str2, block_size=2, max_distance=10)
res = distance_utf(str1.unpack("U*"), str2.unpack("U*"), block_size, max_distance)
(res > max_distance) ? nil : res