Skip to content

Instantly share code, notes, and snippets.

@raghothams
raghothams / fastai-dose.ipynb
Created August 12, 2018 08:47
Idly Dose vade classifier FastAI
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raghothams
raghothams / read-access.sql
Created May 26, 2018 06:38 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@raghothams
raghothams / numpy_array_cell.ipynb
Created March 5, 2018 17:06
numpy array as pandas cell
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raghothams
raghothams / conf.md
Last active January 25, 2018 18:20
docker connect host db to container

Connect to host db from docker container

  1. modify /etc/postgresql/9.5/main/postgresql.conf

add listen_addresses = '*'

  1. modify /etc/postgresql/9.5/main/pg_hba.conf

add host all all 0.0.0.0/0 trust

@raghothams
raghothams / nb.ipynb
Created March 9, 2017 14:21
extract procedure id pyspark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raghothams
raghothams / demography_mapper.py
Last active September 19, 2017 03:01
Spark 2.X MongoDB
from pyspark.sql import SparkSession
spark = SparkSession \
.builder \
.appName("demography mapper") \
.getOrCreate()
df_user = spark.read.format("com.mongodb.spark.sql.DefaultSource")\
.option("spark.mongodb.input.uri", "mongodb://localhost:27017/raw.user").load()
@raghothams
raghothams / d3-word-cloud.js
Created October 6, 2016 17:15
Fix word cloud spacing
d3.layout.cloud().size([1200, 600])
.words([
".NET", "Silverlight", "jQuery", "CSS3", "HTML5", "JavaScript", "SQL","C#"].map(function(d) {
return {text: d, size: 10 + Math.random() * 50};
}))
.rotate(0)
.fontSize(function(d) { return d.size; })
.padding(5)
.spiral("archimedean")
.rotate(function() { return ~~(Math.random() * 2) * 90; })
@raghothams
raghothams / pg_stat.sql
Created July 31, 2016 04:08
postgres check number of open connections
select *
from pg_stat_activity
where datname = 'db_name'
@raghothams
raghothams / co2.ipynb
Created May 22, 2016 13:29
co2 emmision plot
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raghothams
raghothams / server.py
Created February 22, 2016 10:10
Flask request header decorator
from functools import wraps
from flask import Flask, request
app = Flask(__name__)
key = "ya29.bwLu0ruxXdXe_RMOSYgfiCPORNMHLkf9rCDmV1rKtWu90TuF1d8B2SmdUlrjeOWNYThkgMM"
def secure(f):
@wraps(f)
def check_authorization(*args, **kwargs):
if request.headers.get("Authorization") == key:
return f()