Skip to content

Instantly share code, notes, and snippets.

@sudhirj
sudhirj / bunny.js
Created June 21, 2023 06:49
Bunny Token Signer
const getSignedBunnyUrl = function(opts) {
const expiryStamp = Math.floor(opts.expiry.getTime() / 1000)
const token = createHash('sha256').update(opts.token).update(opts.url).update(expiryStamp.toString()).digest('base64url')
return `${opts.url}?token=${token}&expires=${expiryStamp.toString()}`
}
@sudhirj
sudhirj / keybase.md
Created February 10, 2021 15:17
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@sudhirj
sudhirj / handler.go
Created April 9, 2019 05:52
Websocket handling
func (h *HTTPAdapter) Socket(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
conn, err := socketUpgrader.Upgrade(w, r, http.Header{})
if err != nil {
http.Error(w, "Socket could not be established", http.StatusExpectationFailed)
return
}
h.switchboard.Connect(h.topic, conn)
conn.SetCloseHandler(func(code int, text string) error {
h.switchboard.Disconnect(h.topic, conn)
func (h HTTPAdapter) CreateImage() httprouter.Handle {
return h.Authenticated(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
MaxSize := 10000000
if r.ContentLength > int64(MaxSize) {
http.Error(w, "FILE TOO BIG", 413)
return
}
imageBytes, err := ioutil.ReadAll(io.LimitReader(r.Body, r.ContentLength))
/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/bin/java -ea -javaagent:/Users/sudhir/.flow/resources/javaagent.jar -Dflow.agent.kafka-server=localhost:60664 -Dflow.agent.execution-name=GameTest.benchmarkRunningOnRandomBoard -Dflow.agent.autostart -Dflow.agent.include=io.sudhir.switchboard -Didea.test.cyclic.buffer.size=1048576 "-javaagent:/Users/sudhir/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/172.4343.14/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=65502:/Users/sudhir/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/172.4343.14/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Users/sudhir/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/172.4343.14/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Users/sudhir/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/172.4343.14/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/sudhir/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/172.4343.14/IntelliJ ID
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '~> 4.1'
gem 'pg'
GEMFILE
system 'bundle'
end
@charset UTF-8;
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td {
border:0;
outline:0;
font-weight:inherit;
font-style:inherit;
font-size:100%;
font-family:inherit;
vertical-align:baseline;
@sudhirj
sudhirj / gist:5611509
Last active December 17, 2015 12:39
The google ruby client docs on Github neglect to provide examples for the service account flow. This is saved off the old Google Code page.

###Authorization Most interactions with Google APIs require users to authorize applications via OAuth 2.0. The client library uses Signet to handle most aspects of authorization. For additional details about Google's OAuth support, see Google Developers.

Credentials can be managed at the connection level, as shown, or supplied on a per-request basis when calling execute. For server-to-server interactions, like those between a web application and Google Cloud Storage, Prediction, or BigQuery APIs, use service accounts. Assertions for service accounts are made with Google::APIClient::JWTAsserter.

client = Google::APIClient.new
key = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret')
service_account = Google::APIClient::JWTAsserter.new(
    '123456-abcdef@developer.gserviceaccount.com',

'https://www.googleapis.com/auth/prediction',

{
"description":"Back in October, we reported on Quora's attempts at recognizing around 500 of its most valuable users with its new Top Writers badge.\r\n\r\nThe move was largely taken to recognize Quora's ...",
"author":"Paul Sawers",
"url":"http://thenextweb.com/media/2013/01/15/quoras-top-writers-book-2010-2012-is-now-available-download-for-free/",
"image":"http://cdn.thenextweb.com/wp-content/blogs.dir/1/files/2013/01/BestofQuora2-300x250.jpg",
"shortlink":"http://thenextweb.com/?p=547260",
"og":{
"site_name":"The Next Web",
"image":"http://cdn.thenextweb.com/wp-content/blogs.dir/1/files/2013/01/BestofQuora2-300x250.jpg",
"type":"article",
@sudhirj
sudhirj / gist:3213493
Created July 31, 2012 04:04
Method Behind Madness: The Real Reason Apple Made Those Ads

Apple recently released a [set][ad1] of [new][ad2] [ads][ad3] that have met with widespread criticism from the tech community. While I don't really like the ads myself, it actually seems like a good idea for Apple to have made them.

The moment I looked at them here's what came to mind: Apple has moved on. The geeks of the world are no longer prime targets for Apple. Neither are our friends and acquaintances. If you've read [Crossing the Chasm][ctc], Moore talks about five kinds of audiences that need to be addressed: innovators, early adopters, early majority, late majority and laggards. Any guesses which group Apple needs to target now? No? Didn't think so.

Apple has already finished marketing to us (if you're reading this off HN or Reddit, people like you and me), our circle of friends, and our friend's friends. There isn't anyone in these three circles who doesn't know what Apple, Macs, iPhones, iPads and iPods