Skip to content

Instantly share code, notes, and snippets.

@pranavraja
pranavraja / awsutil.ex
Created May 6, 2022 00:15
Utility to fetch AWS credentials for use with aws-beam/aws-elixir, the same way the AWS CLI does it (including support for roles)
defmodule AWSUtil do
def profile(name) do
{:ok, config} = ConfigParser.parse_file(Path.expand("~/.aws/credentials"))
case ConfigParser.get(config, name, "source_profile") do
nil ->
AWS.Client.create(
ConfigParser.get(config, name, "aws_access_key_id"),
ConfigParser.get(config, name, "aws_secret_access_key"),
ConfigParser.get(config, name, "region")
@pranavraja
pranavraja / readme.txt
Created November 16, 2018 23:43
Trials and tribulations (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@pranavraja
pranavraja / README.md
Created April 26, 2018 05:15
Simpler version of jq

Ok jq is great but sometimes i just need to select/filter a field or two

Example usage:

$ curl https://now.httpbin.org | json now rfc3339
"2018-04-26T05:10:00.78Z"

$ echo '[{"id": 1, "title":"Hello"}, {"id": 2, "title":"Goodbye"}]' | json title=Hello id
[

1

@pranavraja
pranavraja / transcode.go
Created April 21, 2017 05:02
Stream/transcode video in real time with ffmpeg for chromecast
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
@pranavraja
pranavraja / README.md
Last active August 29, 2015 14:14
Find when stuff happened in elasticsearch

Suppose you had an elasticsearch query but want to find out the time period during which the query would return results (for example, when tracking a spike in latency/load on a service).

Running esbisect '<query>' will give you the time period (within the last two days) during which the events occured.

e.g. assuming you track events of type http-transaction with a field latencySeconds, running

esbisect 'http://yourelasticsearch.host:9200/_search?q=eventType:http-transaction%20AND%20latencySeconds:{10%20TO%20*}'

Would find the period within the last two days in which the latency spiked above 10 seconds.

@pranavraja
pranavraja / README.md
Last active August 29, 2015 14:06
JSON filter tool

JSON filter tool

Syntax

json takes input from stdin and pretty-prints to stdout. With no arguments it behaves like python -mjson.tool.

When given arguments, each argument is either a field selector or a filter.

echo '{ "a": { "b": "c"} }' | json a selects the field a and prints {"b": "c"}

@pranavraja
pranavraja / main.go
Created June 12, 2014 08:30
Environment variable helper
// Build this using `go build` and put it in your PATH
package main
import (
"encoding/json"
"os"
"os/exec"
"strings"
)
@pranavraja
pranavraja / main.go
Created February 27, 2014 03:32
Go proxy server
package main
import (
"flag"
"fmt"
"io"
"net/http"
"net/url"
"strings"
)
@pranavraja
pranavraja / main.go
Last active December 20, 2015 07:39
Caching proxy for the npm registry
package main
import (
"github.com/golang/groupcache"
"github.com/gorilla/mux"
"github.com/pranavraja/front/cache"
"bytes"
"flag"
"io/ioutil"
@pranavraja
pranavraja / objcmethods.py
Created May 31, 2013 01:59
Count length of methods in iOS codebases
import sys
from collections import defaultdict
def name_of_method(signature):
start_method_name = signature.find(')') + 1
end_method_name = signature.rfind('{')
return signature[start_method_name:end_method_name]
if __name__ == '__main__':
if len(sys.argv) <= 1: