Skip to content

Instantly share code, notes, and snippets.

View Kasahs's full-sized avatar

Shasak Raina Kasahs

  • O4S
  • Gurugram, India
View GitHub Profile
@Kasahs
Kasahs / pubsubExample.js
Last active September 15, 2015 13:00
simple javascript pubsub example
var PubSub = (function(){
var mapping = {};
return {
sub: function(eventName, callback, obj){
callback = callback || _.noop;
if(!_.isFunction(callback)){
console.error("callback is not a function");
return;
}
@Kasahs
Kasahs / .eslintrc
Created November 26, 2015 10:56
eslintrc based on google style guide with a few mods.
{
"env": {
"browser": true, // browser global variables.
"node": false, // Node.js global variables and Node.js-specific rules.
"worker": false, // web workers global variables.
"amd": false, // defines require() and define() as global variables as per the amd spec.
"mocha": false, // adds all of the Mocha testing global variables.
"jasmine": false, // adds all of the Jasmine testing global variables for version 1.3 and 2.0.
"phantomjs": false, // phantomjs global variables.
"jquery": true, // jquery global variables.
@Kasahs
Kasahs / stacked-column-chart.html
Last active December 8, 2015 14:48
Highcharts stacked vertical column graph config.
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
@Kasahs
Kasahs / factory-service-provider.js
Last active December 19, 2015 10:13
A simple example to show difference between them and usage style.
// @see http://stackoverflow.com/a/17944367/2317794
var myApp = angular.module('myApp', []);
//Service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
};
});
@Kasahs
Kasahs / header_gen.py
Last active January 28, 2016 08:25
To generate new headers for scraping purposes.
"""
Expose methods to return new header dictionary. Supports only GET requests at the moment.
(Using phantomJS to throw them off. Maybe overkill. Could have used simple get request.)
"""
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# edit desired capabilities
dcap = dict(DesiredCapabilities.PHANTOMJS)
@Kasahs
Kasahs / pymongo_essentials.py
Created January 28, 2016 08:28
Some essential functions for connecting to mongodb, adding data to a collection etc. using pymongo.
from pymongo import MongoClient
def get_db():
try:
connection = MongoClient('localhost', 27019)
db = connection['db_name']
collection = db['collection_name']
return collection, connection
except Exception as e:
@Kasahs
Kasahs / ssl_adapter.py
Last active January 28, 2016 08:34
To solve 'EOF occurred in violation of protocol' error when using the python requests module
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl
class MyAdapter(HTTPAdapter):
"""Create http adapter that uses TLSv1 protocol."""
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
@Kasahs
Kasahs / english_prefix_list.py
Created January 28, 2016 08:36
A list of 4 letter(max) prefixes derived from a list of common words in English.
prefixes = ["", "&c", "'d", "'em", "'ll", "'m", "'mid", "'mon", "'pre", "'re", "'s", "'sbl", "'sbo", "'sde", "'sfo", "'she", "'shu", "'sli", "'sna", "'str", "'t", "'til", "'tis", "'twa", "'twe", "'twi", "'two", "'un", "'ve", "1080", "10th", "1st", "2", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "a", "a'", "a's", "a/c", "a1", "aa", "aaa", "aah", "aahe", "aahi", "aahs", "aal", "aali", "aals", "aam", "aard", "aarg", "aaro", "aarr", "aas", "aasv", "ab", "aba", "abac", "abad", "abaf", "abai", "abak", "abal", "abam", "aban", "abap", "abar", "abas", "abat", "abau", "abav", "abax", "abay", "abaz", "abb", "abba", "abbe", "abbo", "abbr", "abby", "abc", "abce", "abci", "abco", "abd", "abda", "abde", "abdi", "abdo", "abdu", "abe", "abea", "abec", "abed", "abeg", "abei", "abel", "aben", "abep", "aber", "abes", "abet", "abev", "abey", "abfa", "abhe", "abhi", "abho", "abib", "abic", "abid", "abie", "abig", "abil", "abim", "abin", "abio", "abir", "abis", "abit", "abiu", "abje", "abjo", "abju", "abka", "abl", "ab
@Kasahs
Kasahs / mask.js
Last active March 1, 2016 09:03
mask all but last 4 characters of a string
// source: http://stackoverflow.com/a/27545357/2317794
var str = "1238127397812378"
str = str.replace(/\d(?=\d{4})/g, "*");
@Kasahs
Kasahs / angular-unload.js
Created March 14, 2016 11:03
Angular page unload prevention dialog
vm.unloadWatcher = $scope.$on('$locationChangeStart', function(event, next, current) {
if(!confirm("Are you sure you want to leave this page?")) {
event.preventDefault();
}
});
$scope.$on('$destroy', function(){
vm.unloadWatcher();
});