Skip to content

Instantly share code, notes, and snippets.

View venkatperi's full-sized avatar

Venkat Peri venkatperi

View GitHub Profile
li#grades_menu_item {
display: none;
visibility: none;
}
@venkatperi
venkatperi / CGContextExt.swift
Created April 24, 2015 20:54
CGContext Syntactic Sugar
// CGContextABCD(context!, ...) becomes context?.ABCD(...)
import Cocoa
extension CGContext {
func saveGState() { CGContextSaveGState(self) }
func restoreGState() { CGContextRestoreGState(self) }
func scaleCTM( sx: CGFloat, sy: CGFloat) { CGContextScaleCTM(self, sx, sy) }
func translateCTM( tx: CGFloat, ty: CGFloat) { CGContextTranslateCTM(self, tx, ty) }
func rotateCTM( angle: CGFloat) { CGContextRotateCTM(self, angle) }
@venkatperi
venkatperi / aws-apigateway-nodejs.coffee
Created August 17, 2015 18:29
REST acess AWS ApiGatetwy in nodejs. Uses "private" AWS v4 signer.
AWS = require "aws-sdk"
https = require "https"
creds =
accessKeyId: "<<ACCESS KEY ID>>"
secretAccessKey: "<<SECRET ACCESS KEY>>"
opts =
method: "GET"
pathname: -> '/restapis'
@venkatperi
venkatperi / keygen.coffee
Created August 25, 2015 02:56
Generate base62 api keys
crypto = require "crypto"
chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
module.exports = ( size = 40 ) ->
throw "bad size" if size < 1
key = ""
bytes = crypto.randomBytes( size * 3 )
j = 0
while key.length < size
@venkatperi
venkatperi / requestTemplate.vtl
Created August 25, 2015 02:59
General purpose request template for AWS Api Gateway methods. Use with /{resource}
#set($root = $input.path('$'))
#set($res = {"method":"$context.httpMethod", "resource":"$input.params('resource')", "requestId":"$context.requestId" })
#set( $optional = ["Authorization", "X-MyApp-Api-Token"])
#foreach ($x in $optional)
#if ($input.params($x).length() > 0)
#set( $res[$x.toLowerCase()] = $input.params($x))
#end
@venkatperi
venkatperi / pseq.js
Created June 25, 2017 01:53
Execute array of promises in sequence
pseq = ( arr ) => arr.reduce(
( r, n ) => r.then( typeof n === 'function' ? n : () => Promise.resolve( n ) ),
Promise.resolve() );
@venkatperi
venkatperi / com.vperi.homebrew-update.plist
Created January 31, 2018 16:43
home-brew LaunchAgent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin</string>
@venkatperi
venkatperi / IterableExtSpec.kt
Last active April 11, 2018 15:24
Kotlin: Split Iterable into two at given index
object IterableExtSpec : Spek({
val list = (0 until 100).toList()
describe("splitAt") {
it("asserts when n < 0") {
assertFailsWith<IllegalArgumentException> {
list.splitAt(-2)
}
}
class MovingAverageWithRate(object):
"""
Computes the moving average (with optional sample rate) of supplied
samples over a given window size.
Add new samples with add()
"""
def __init__(self, window_size):
@venkatperi
venkatperi / custom.css
Created August 30, 2018 18:11
Tweeten.app Custom CSS for dark/compact mode
html .system-font-stack {
font-weight: 200 !important;
font-family: "mplus-1c-light" !important;
font-size: 12px !important;
color: #748FB4 !important;
}
.js-app .js-column .stream-item .js-tweet-text {
color: #748FB4 !important;
}