Skip to content

Instantly share code, notes, and snippets.

View lordloh's full-sized avatar

Bharath Bhushan Lohray lordloh

View GitHub Profile
@lordloh
lordloh / clearcache.sh
Last active August 22, 2018 00:02
This is a script I use to free up memory on my system. It syncs all IO buffers to disk, then instructs the kernel to drop all caches. However, caches exist for a reason. Manually clearing them will temporarily degrade application performance.
#! /bin/bash
free -m
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
free -m
@lordloh
lordloh / localDate.js
Created April 17, 2018 03:07
A snippet to get the local date in JavaScript
var today = new Date();
var localToday = new Date(today.getTime()-today.getTimezoneOffset()*60000);
var localToday_str=localToday.toISOString().substring(0, 10);
console.log(localToday_str);
@lordloh
lordloh / card_mask.m
Created October 30, 2017 23:04
A MATLAB function to generate a mask for playing cards
function mask=card_mask(img)
BW_a=imbinarize(img,'adaptive');
BW_g=imbinarize(img,'global');
cc_a=bwconncomp(BW_a,4);
cc_g=bwconncomp(BW_g,4);
obj_sizes_a=cellfun('length',cc_a.PixelIdxList);
obj_sizes_g=cellfun('length',cc_g.PixelIdxList);
[px_count_a,idx_a]=max(obj_sizes_a);
[px_count_g,idx_g]=max(obj_sizes_g);
mask=false(size(img));
@lordloh
lordloh / bool2str.m
Last active June 16, 2017 21:17
MATLAB function to convert Boolean values to String.
function [ out_cell ] = bool2str( bool_in,varargin)
%BOOL2STR Converts boolean values to string.
% BOOL2STR(B) returns a cell of 'True' or 'False' corresponding to the
% boorean values supplied in vector B.
%
% BOOL2STR(B,{'Noooo!','Yeah!'}) takes custom stings to correspond to the
% boolean values.
%
% Example:
% bool2str(logical([1 0 0 1]),{'Noooo!','Yeah!'})
@lordloh
lordloh / bslikeresponsive.css
Last active April 19, 2017 03:34
A CSS skeleton extracted from bootstrap.css to define responsive classes.
/*
A CSS skeleton extracted from bootstrap.css to define responsive classes.
Make sure you define classes for each screen size and you should have a responsive design :-)
*/
/* print */
@media print {
}
/* universal */
@lordloh
lordloh / sp500.py
Created November 3, 2016 22:21
S & P 500 List
# The S&P 500 Stock List.
# From - https://en.wikipedia.org/wiki/List_of_S%26P_500_companies
#
# Bharath Bhushan Lohray
#
S_P_500 = ['MMM', 'ABT', 'ABBV', 'ACN', 'ATVI', 'AYI', 'ADBE', 'AAP', 'AES', 'AET', 'AFL', 'AMG', 'A', 'APD', 'AKAM', 'ALK', 'ALB', 'AGN', 'LNT', 'ALXN', 'ALLE', 'ADS', 'ALL', 'GOOGL', 'GOOG', 'MO', 'AMZN', 'AEE', 'AAL', 'AEP', 'AXP', 'AIG', 'AMT', 'AWK', 'AMP', 'ABC', 'AME', 'AMGN', 'APH', 'APC', 'ADI', 'ANTM', 'AON', 'APA', 'AIV', 'AAPL', 'AMAT', 'ADM', 'ARNC', 'AJG', 'AIZ', 'T', 'ADSK', 'ADP', 'AN', 'AZO', 'AVB', 'AVY', 'BHI', 'BLL', 'BAC', 'BK', 'BCR', 'BAX', 'BBT', 'BDX', 'BBBY', 'BRK', 'BBY', 'BIIB', 'BLK', 'HRB', 'BA', 'BWA', 'BXP', 'BSX', 'BMY', 'AVGO', 'BF', 'CHRW', 'CA', 'COG', 'CPB', 'COF', 'CAH', 'HSIC', 'KMX', 'CCL', 'CAT', 'CBG', 'CBS', 'CELG', 'CNC', 'CNP', 'CTL', 'CERN', 'CF', 'SCHW', 'CHTR', 'CHK', 'CVX', 'CMG', 'CB', 'CHD', 'CI', 'XEC', 'CINF', 'CTAS', 'CSCO', 'C', 'CFG', 'CTXS', 'CLX', 'CME', 'CMS', 'COH', 'KO', 'CTSH', 'CL', 'CMCSA', 'CMA', 'CAG', 'CXO', 'COP', 'ED', 'S
@lordloh
lordloh / do_offline_backups.sh
Last active October 27, 2016 07:53
A script to backup chosen folders to an offline USB hard disk drive.
#! /bin/bash
# Code by Bharath Bhushan Lohray
# https://bharath.lohray.com/
# github: lordloh
# bitbucket: lordloh
PART_ID="926fc38e-bc7e-467a-953e-25c6555939a0"
now=$(date)
echo "===== Running at $now ====="
@lordloh
lordloh / credentials_for_python
Last active May 15, 2021 02:58
A snippet to avoid hard coding user names and passwords in python scripts.
# If you hardcode usernames and passwords, you cannot check in the code to public git repositories.
# A solution I am using is to create a `credentials.json` file and storing the password there
# cerdentials.json :
# {
# "user":"bharath",
# "password":"bharath_secret_password"
# }
#
# add this file to .gitignore
#
@lordloh
lordloh / YQL: Get historic stock data
Last active October 21, 2016 05:24
Python functions to get historic stock data.
# Python functions to get historic stock data.
# Use the yql_stock_long_history wrapper. Yahoo does not return data if long requests are made -
# For example GOOG form 2001-01-01 to today. The wrapeer breaks the query into multiple 1y queries
# and combines the results
import json
import urllib
import time
from datetime import datetime, timedelta, date
@lordloh
lordloh / robinhood_cache_instrument
Last active October 18, 2016 05:52
A snippet that helps cache the instrument -> stock symbol API request.
# Code by Bharath Bhushan lohray
# https://bharath.lohray.com/
# github: lordloh
# bitbuckte: lordloh
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]