Skip to content

Instantly share code, notes, and snippets.

{
"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: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',

@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;
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '~> 4.1'
gem 'pg'
GEMFILE
system 'bundle'
end
/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
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))
@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)
@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 / 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()}`
}