Skip to content

Instantly share code, notes, and snippets.

View 00krishna's full-sized avatar

Krishna Bhogaonker 00krishna

  • Student, UCLA
  • Los Angeles, CA, USA
View GitHub Profile
//Find zombie processes
ps aux | grep 'Z'
//Find the parent processes for the zombie
pstree -p -s 93572
//Note that 93572 is just a number, you can enter your own number
//kill parent process
kill <parent process id>
@00krishna
00krishna / AbstractDataRequest.h
Created April 19, 2017 21:50
This is an empty abstract class. I used it as a way to group subclasses so that I can pass them as arguments to function.
#ifndef TVASTRCPP_ABSTRACTDATAREQUEST_H
#define TVASTRCPP_ABSTRACTDATAREQUEST_H
class AbstractDataRequest {
virtual ~dummyFunc() = 0;
};
-- As David Fetter kindly pointed out, this looks cleaner, returns one record per ddl and is more psql friendly
SELECT 'ALTER TABLE ' || quote_ident(c.table_schema) || '.'
|| quote_ident(c.table_name) || ' RENAME "' || c.column_name || '" TO ' || quote_ident(lower(c.column_name)) || ';' As ddlsql
FROM information_schema.columns As c
WHERE c.table_schema NOT IN('information_schema', 'pg_catalog')
AND c.column_name <> lower(c.column_name)
ORDER BY c.table_schema, c.table_name, c.column_name;
-- lower case table names -- the psql friendly and more reader-friendly way
SELECT 'ALTER TABLE ' || quote_ident(t.table_schema) || '.'
|| quote_ident(t.table_name) || ' RENAME TO ' || quote_ident(lower(t.table_name)) || ';' As ddlsql
FROM information_schema.tables As t
WHERE t.table_schema NOT IN('information_schema', 'pg_catalog')
AND t.table_name <> lower(t.table_name)
ORDER BY t.table_schema, t.table_name;
--generates something like this
--ALTER TABLE public."SPRINT" RENAME TO sprint;
@00krishna
00krishna / average4.sql
Created March 30, 2016 23:42
take the average of 4 numbers, guarding for null values.
CREATE OR REPLACE FUNCTION AVERAGE4 (
V1 NUMERIC,
V2 NUMERIC,
V3 NUMERIC,
V4 NUMERIC)
RETURNS NUMERIC
AS $FUNCTION$
DECLARE
COUNT NUMERIC;
TOTAL NUMERIC;
@00krishna
00krishna / st_intersect_query.sql
Created March 16, 2016 20:59
postgis update query where there is an intersection
update census_tracts_2014
set council_district = t1.dist
from (select council_districts.dist, census_tracts_2014.affgeoid, council_districts.geom
from census_tracts_2014 inner join council_districts
on
ST_Intersects(census_tracts_2014.geom, ST_Transform(council_districts.geom,4269))) t1
where
ST_Intersects(census_tracts_2014.geom, ST_Transform(t1.geom,4269));
@00krishna
00krishna / install_postgis.sql
Created December 28, 2015 21:28
setup postgis on a database
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
@00krishna
00krishna / optional_decorator_function.py
Created December 9, 2015 06:43
create an optional decorator
class OptionalDecoratorDecorator(object):
def __init__(self, decorator):
self.deco = decorator
def __call__(self, func):
self.deco = self.deco(func)
self.func = func
def wrapped(*args, **kwargs):
@00krishna
00krishna / progressive_progressbar.py
Last active September 7, 2015 17:31
Python progressive progressbar working example
__author__ = 'krishnab'
from time import sleep
from blessings import Terminal
from progressive.bar import Bar
from progressive.tree import ProgressTree, Value, BarDescriptor
@00krishna
00krishna / pdfxtract.py
Last active August 29, 2015 14:19 — forked from jmcarp/pdfxtract.py
"""
Extract PDF text using PDFMiner. Adapted from
http://stackoverflow.com/questions/5725278/python-help-using-pdfminer-as-a-library
"""
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter#process_pdf
from pdfminer.pdfpage import PDFPage
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams