Skip to content

Instantly share code, notes, and snippets.

View tarunc's full-sized avatar

Tarun Chaudhry tarunc

  • San Francisco, CA
View GitHub Profile
@tarunc
tarunc / insert_image_on_pdf.rb
Created August 1, 2021 05:16 — forked from aashish/insert_image_on_pdf.rb
Insert image on a existing PDF having content with hexapdf gem
require 'hexapdf'
doc = HexaPDF::Document.open("/home/xxxx/Downloads/OoPdfFormExample.pdf")
page = doc.pages[0]
canvas = page.canvas(type: :overlay)
canvas.translate(0, 20) do
canvas.fill_color(0.3, 0.7, 0.7)
canvas.rectangle(50, 0, 80, 80, radius: 80)
@tarunc
tarunc / webpack4upgrade.md
Created April 3, 2018 15:33 — forked from gricard/webpack4upgrade.md
Just some notes about my attempt to upgrade to webpack 4

This is not a complaint about Webpack or v4 in any way. This is just a record of my process trying it out so I could provide feedback to the webpack team

Hmm... I don't see any docs for 4.0 on https://webpack.js.org. I guess I'll just wing it. All I need to do is npm i -D webpack@next, right?

+ [email protected]
added 1 package, removed 20 packages and updated 4 packages in 13.081s
@tarunc
tarunc / sweeten-docco.sh
Created May 18, 2014 23:45
sweeten-docco.sh
#!/bin/bash
# sweeten-docco.sh ./docker-docs-folder
# Sweeten docco output with syntax highlighted JSDoc and Codo tags.
# Builds sed command for the current os
sed_cmd() {
local cmd=''
local os=$( uname )
case $os in
#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford ([email protected])
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
# This method finds related articles using Jaccard index (optimized for PostgreSQL).
# More info: http://en.wikipedia.org/wiki/Jaccard_index
class Article < ActiveRecord::Base
def related(limit=10)
Article.find_by_sql(%Q{
SELECT
a.*,
( SELECT array_agg(t.name) FROM taggings tg, tags t
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
@tarunc
tarunc / auth.py
Last active December 25, 2015 07:49 — forked from mjallday/auth_server.py
import SimpleHTTPServer
import SocketServer
PORT = 8000
class Server(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
headers = self.headers.dict
print headers.get('x-original-uri')
@tarunc
tarunc / kmeans.js
Created July 19, 2012 08:58
K-Means Clustering in Javascript
var distances = {
euclidean: function(v1, v2) {
var total = 0;
for (var i = 0; i < v1.length; i++) {
total += Math.pow(v2[i] - v1[i], 2);
}
return Math.sqrt(total);
},
manhattan: function(v1, v2) {
var total = 0;