Skip to content

Instantly share code, notes, and snippets.

@rajeshg
rajeshg / cfworker - cache images
Created March 14, 2022 14:18
cache images from origin, resize and convert to avif/webp
// https://developers.cloudflare.com/images/resizing-with-workers
// https://developers.cloudflare.com/workers/examples/cache-api/
addEventListener('fetch', (event) => {
if (/image-resizing/.test(event.request.headers.get("via"))) {
return fetch(event.request)
}
event.respondWith(handleRequest(event))
})
async function handleRequest(event) {
let request = event.request
@rajeshg
rajeshg / sync-meetings.ps1
Last active March 3, 2021 03:35
powershell script to sync to a local calendar
#
# Usage: .\sync-meetings.ps1
#
$DebugPreference = "Continue"
$VerbosePreference = "SilentlyContinue"
Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
@rajeshg
rajeshg / useful.sh
Last active September 13, 2018 14:42
useful commands
# speed test from command line - https://askubuntu.com/questions/104755/how-to-check-internet-speed-via-terminal
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -
# vagrant commands
vagrant box add ubuntu/bionic64 # to download ubuntu bionic64 images. More can be found at vagrantcloud.com
vagrant init bionic64 # to initialize a vm using the image we downloaded
vagrant up # to turn on the box that we initialized
vagrant ssh # to ssh into the box
vagrant reload --provision # to reload after editing Vagrantfile
@rajeshg
rajeshg / gist:737730
Created December 12, 2010 00:04
isOdd
public boolean isOdd(int i) { return (i & 1) != 0; }
@rajeshg
rajeshg / mkcd.bash
Created November 23, 2010 19:01
mkcd command - how to create a directory using mkdir and cd in one step
#
# mkcd command
# This is an improvised version of the mkcd command at http://superuser.com/questions/152794/is-there-a-shortcut-to-mkdir-foo-and-immediately-cd-into-it
# This function has to be added to the ~/.bashrc file
# After that you can run command like: mkdir abc, mkdir -p one/two/three
#
function mkcd {
last=$(eval "echo \$$#")
if [ ! -n "$last" ]; then
echo "Enter a directory name"
@rajeshg
rajeshg / gist:664217
Created November 5, 2010 14:23
Delicious bookmarklet which opens the delicious url in a seperate window. This is a slightly modified version of the official delicious bookmarklet
javascript:(function(){window.open('http://www.delicious.com/save?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&v=5&jump=doclose');})()
@rajeshg
rajeshg / exportTwitterFavorites.rb
Created October 29, 2010 20:17
Ruby script to export Twitter favorites to a CSV file
#!/usr/bin/ruby -w
# author: rgollapudi
# description: Script to fetch all your twitter favorites and write them to a csv file
require 'open-uri'
require 'rss/1.0'
require 'rss/2.0'
# For reading rss from a url:
@rajeshg
rajeshg / gist:642443
Created October 23, 2010 17:04
Handy unix commands
# How to remove empty png files in a directory
find ./ -name "*.png" -size 0 -exec rm {} \;
# How to remove all empty files in a directory
find ./ -name "*" -size 0 -exec rm {} \;
# How to remove all .DS_Store files from a directory in Mac OS X
find . -name '*.DS_Store' -type f -delete
# How to set 755 permissions on all directories and 646 for all files
@rajeshg
rajeshg / meta-fetcher.rb
Created October 15, 2010 19:46
Quick little script to fetch all the meta tags from a website and export them to excel
#!/usr/bin/ruby -w
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'spreadsheet'
class MetaReader
attr_reader :url, :outFile, :links, :book, :sheet1, :rownum
attr_accessor :url, :outFile, :links, :book, :sheet1, :rownum
#!/usr/local/bin/ruby -w
require 'csv'
CSV.foreach("contacts.csv") do |row|
name = row[0]
if name.nil?
# do nothing
elsif name.empty?
# do nothing
else
command = "google calendar add --cal \"Finelighters Birthdays\" \"#{name}'s Birthday #{row[1]}\""