Skip to content

Instantly share code, notes, and snippets.

Avatar

Prasanna Swaminathan pswaminathan

View GitHub Profile
@andrestc
andrestc / go-missing-examples.md
Last active Sep 4, 2018
Go std lib funcs/methods missing examples
View go-missing-examples.md

About this

This list has the goal of helping developers interested in contributing to the Go language but are unsure of where to start. This was not generated manually so some functions and methods here may not require examples (maybe because they are too simple, e.g .String()) and some of these may only make sense in a package level example (which are not considered for this list yet). Use your best judgment and check the documentation before you open up a CL to add an example.

You should also search in gerrit for open CLs that are already adding examples.

I will try to keep this list as up to date as possible. If you find any mistakes, please comment below and I will try to fix it.

@swankjesse
swankjesse / MoshiKotlinExample.kt
Created May 14, 2017
Demo how to use Moshi with Kotlin
View MoshiKotlinExample.kt
import com.squareup.moshi.Json
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import java.util.Date
val json = """
{
"url": "https://api.github.com/repos/square/okio/issues/156",
"id": 91393390,
@jessfraz
jessfraz / j3ss.co.conf
Created Oct 1, 2016
nginx go-get vanity urls
View j3ss.co.conf
server {
....
location ~ ^/x/(.*) {
if ($args = "go-get=1") {
add_header Content-Type text/html;
return 200 '<meta name="go-import" content="$host/x/$1 git https://github.com/jessfraz/$1.git">';
}
return 302 https://github.com/jessfraz/$1;
}
@blha303
blha303 / compliment.b303.me.py
Last active May 3, 2018
Gets random comment from /r/gonewild, since they're pretty much all compliments. http://compliment.b303.me Warning: May contain sexual content
View compliment.b303.me.py
#!/usr/bin/env python3
import requests
from flask import *
import random
from apscheduler.schedulers.background import BackgroundScheduler
app = Flask(__name__)
scheduler = BackgroundScheduler()
url = "https://reddit.com/r/gonewild/comments.json?limit=200"
@paragonie-scott
paragonie-scott / crypto-wrong-answers.md
Last active Aug 1, 2020
An Open Letter to Developers Everywhere (About Cryptography)
View crypto-wrong-answers.md
@ygotthilf
ygotthilf / jwtRS256.sh
Last active Sep 28, 2020
How to generate JWT RS256 key
View jwtRS256.sh
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@ipmb
ipmb / ratelimit.nginxconf
Last active Aug 26, 2020
Nginx reverse proxy with rate limiting
View ratelimit.nginxconf
upstream myapp {
server 127.0.0.1:8081;
}
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 443 ssl spdy;
server_name _;
View goi.md

Interfaces

Let's imagine a very simple table

CREATE TABLE people {
  id bigserial,
  name character varying
}
View dbmanager.go
// Use Case:
//
// Say you have a bunch of decoupled components which access the same set of databases.
// Since database/sql does connection pooling it makes sense for the components to share instances of *sql.DB
// This package lets you do that with minimal code changes.
package dbmanager
import (
"database/sql"
"time"
@blixt
blixt / flask_cors.py
Created Aug 16, 2014
How to add CORS support to a Flask app in 9 lines of code
View flask_cors.py
def add_cors_headers(response):
response.headers['Access-Control-Allow-Origin'] = '*'
if request.method == 'OPTIONS':
response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
headers = request.headers.get('Access-Control-Request-Headers')
if headers:
response.headers['Access-Control-Allow-Headers'] = headers
return response
app.after_request(add_cors_headers)
You can’t perform that action at this time.