Skip to content

Instantly share code, notes, and snippets.

@vuchau
vuchau / aws.dart
Created October 23, 2020 04:52 — forked from BerndWessels/aws.dart
Flutter AWS Cognito Federated Identities Login
import 'package:amazon_cognito_identity_dart/cognito.dart';
import 'package:amazon_cognito_identity_dart/sig_v4.dart';
import 'package:http/http.dart' as http;
class Credentials {
final CognitoCredentials _cognitoCredentials;
final String _token;
final String _authenticator;
Credentials(String identityPoolId, String userPoolId, String clientId, this._token, [this._authenticator])
@vuchau
vuchau / Makefile
Created March 26, 2020 11:03 — forked from doubleyou/Makefile
grpc-gateway python example
GATEWAY_FLAGS := -I. -I/usr/local/include -I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include
GRPC_FLAGS := --python_out=. --grpc_python_out=.
code:
python -m grpc_tools.protoc $(GRPC_FLAGS) $(GATEWAY_FLAGS) *.proto
gw:
protoc $(GATEWAY_FLAGS) \
--go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \
@vuchau
vuchau / geo.js
Created May 10, 2019 07:33 — forked from mkhatib/geo.js
A Javascript utility function to generate number of random Geolocations around a center location and in a defined radius.
/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
function generateRandomPoints(center, radius, count) {
var points = [];
for (var i=0; i<count; i++) {
@vuchau
vuchau / handlers.go
Created November 12, 2018 03:06 — forked from dstroot/handlers.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"io"
"net/http"
"sync/atomic"
)
func index() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@vuchau
vuchau / main.go
Created November 12, 2018 02:56 — forked from enricofoltran/main.go
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@vuchau
vuchau / README.md
Created October 9, 2018 07:59 — forked from Jc2k/README.md
Database rollback options in Django

Batching migrations

The idea here is that if you know which migrations were in version 2.0.3 of your project and which were in version 2.0.4 then setA - setB gives you the list of migrations you need to undo.

Django migrations give you a directed acyclic graph which describes how to get from the current database state to the target state. But there is no mechanism by which you can perform tasks like revert all the migrations that just ran in the last deployment.

Here is a quick recipe for batching Django migrations to allow you to do things like that.

Before you tag your project you do:

@vuchau
vuchau / TorPrivoxyPython.md
Created June 9, 2018 08:03 — forked from DusanMadar/TorPrivoxyPython.md
A step-by-step guide how to use Python with Tor and Privoxy
@vuchau
vuchau / docker-compose.yml
Created February 6, 2018 16:59 — forked from arthurpham/docker-compose.yml
For Rancher # This compose file stands up Scrapy Cluster with an # associated ELK Stack. You should run a few crawls and then import the # `export.json` file into your Kibana objects
logstash-crawler:
labels:
io.rancher.container.pull_image: always
io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$$$${stack_name}/$$$${service_name}
io.rancher.scheduler.affinity:host_label: role=crawler
command:
- -f
- /etc/logstash/conf.d/logstash.conf
image: arthurpham/logstash-scrapy-cluster-docker:latest
links:
@vuchau
vuchau / useful_pandas_snippets.py
Created December 30, 2017 15:35 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
@vuchau
vuchau / kibana_nginx.conf
Created May 9, 2017 06:25 — forked from sthomp/kibana_nginx.conf
nginx config to proxy connections to kibana on aws
worker_processes 1;
events {
worker_connections 1024;
}
http{
server {
listen 80;
server_name localhost;