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
@00krishna
00krishna / 0_reuse_code.js
Created February 15, 2014 22:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
# -*- coding: utf-8 -*-
"""
LICENSE: BSD (same as pandas)
example use of pandas with oracle mysql postgresql sqlite
- updated 9/18/2012 with better column name handling; couple of bug fixes.
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle.
to do:
save/restore index (how to check table existence? just do select count(*)?),
finish odbc,
@00krishna
00krishna / pandas.postgres.py
Last active March 21, 2022 13:44
Connect from python pandas to a postgresql database and pull data.
import psycopg2 as pg
import pandas.io.sql as psql
# get connected to the database
connection = pg.connect("dbname=mydatabase user=postgres")
dataframe = psql.frame_query("SELECT * FROM <tablename>", connection)
@00krishna
00krishna / linkgetter.py
Created February 15, 2014 23:21
Get all links in a web page
import re, urllib
htmlSource = urllib.urlopen("http://sebsauvage.net/index.html").read(200000)
linksList = re.findall('<a href=(.*?)>.*?</a>',htmlSource)
for link in linksList:
print link
@00krishna
00krishna / filelist.py
Created February 17, 2014 23:53
Get list of files in directory
from os import listdir
from os.path import isfile, join
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
# -*- coding: utf-8 -*-
"""
LICENSE: BSD (same as pandas)
example use of pandas with oracle mysql postgresql sqlite
- updated 9/18/2012 with better column name handling; couple of bug fixes.
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle.
to do:
save/restore index (how to check table existence? just do select count(*)?),
finish odbc,
@00krishna
00krishna / gist:9165405
Created February 23, 2014 01:42
Postgresql: if you are trying to convert a string to an integer, be careful of nulls. Here is a postgres solution.
SELECT
NULLIF(your_value, '')::int
@00krishna
00krishna / pandas_read_csv
Created April 22, 2014 02:24
import csv to python by pandas
from pandas import read_csv
from urllib import urlopen
page = urlopen("http://econpy.pythonanywhere.com/ex/NFL_1979.csv")
df = read_csv(page)
print df
print df['Line']
@00krishna
00krishna / template_plpsql_function
Last active August 29, 2015 14:01
template for plpsql function
-- Function: template_function(OUT result boolean)
-- DROP FUNCTION template_function(OUT result boolean)
CREATE OR REPLACE FUNCTION template_function(OUT result boolean)
AS
$BODY$
DECLARE
BEGIN
@00krishna
00krishna / gist:19313e7dcdfde73fcbd5
Created May 23, 2014 22:13
connect to postgresql database
# Import Libraries
library(RPostgreSQL)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#' Connect to PostgreSQL database
#'
#' This takes a database name and then connects to it.
#' @param dname The name of the database that houses the dlhs data