Skip to content

Instantly share code, notes, and snippets.

View ahlusar1989's full-sized avatar
🏀
Let's Go!

Saran Ahluwalia ahlusar1989

🏀
Let's Go!
View GitHub Profile
# -*- coding: utf-8 -*-
""" Small script that shows hot to do one hot encoding
of categorical columns in a pandas DataFrame.
See:
http://scikit-learn.org/dev/modules/generated/sklearn.preprocessing.OneHotEncoder.html#sklearn.preprocessing.OneHotEncoder
http://scikit-learn.org/dev/modules/generated/sklearn.feature_extraction.DictVectorizer.html
"""
import pandas
import random
@ahlusar1989
ahlusar1989 / stateMock.js
Created May 22, 2016 23:17 — forked from wilsonwc/stateMock.js
Angular Mock for properly resolving ui-router $state in Karma unit tests
angular.module('stateMock',[]);
angular.module('stateMock').service("$state", function($q){
this.expectedTransitions = [];
this.transitionTo = function(stateName){
if(this.expectedTransitions.length > 0){
var expectedState = this.expectedTransitions.shift();
if(expectedState !== stateName){
throw Error("Expected transition to state: " + expectedState + " but transitioned to " + stateName );
}
}else{
import unittest
def foo(x, y, z):
return (x != y and x != z or x and z)
def get_test_args():
x = y = z = [True, False]
from itertools import product, repeat
# for each input arg ---> expected arg
input_args = list(product(x, y, z))
[
{
"title": "How to handle state in React. The missing FAQ.",
"author": "Osmel Mora",
"url": "https://medium.com/react-ecosystem/how-to-handle-state-in-react-6f2d3cd73a0c"
},
{
"title": "You might not need React Router",
"author": "Konstantin Tarkus",
"url": "https://medium.freecodecamp.com/you-might-not-need-react-router-38673620f3d"
@wffurr
wffurr / staqueue.py
Created March 11, 2014 02:26
Queue implementation using two stacks
"""
Implement a queue with two stacks
Interview practice from coding for interviews - March 2014
"""
class Staqueue(object):
""" Implements a queue with two stacks
One stack is used for enqueing, and the other dequeing. If an enqueue is requested
@karmadude
karmadude / README.md
Last active February 7, 2017 08:24
San Francisco Contours
@addyosmani
addyosmani / flyweight.js
Created May 12, 2012 20:19
The Flyweight pattern
// Flyweight.js - Copyright Addy Osmani, 2012.
// Consider public domain
// My implementation in JS of this:
// http://en.wikipedia.org/wiki/Flyweight_pattern
// Simulate pure virtual inheritance/'implement' keyword for JS
Function.prototype.implementsFor = function (parentClassOrObject) {
if (parentClassOrObject.constructor == Function) {
// Normal Inheritance
this.prototype = new parentClassOrObject;
@vasanthk
vasanthk / 00 README.md
Created November 24, 2015 06:36 — forked from istarkov/00 README.md
How to style React components

How to style React components

If you use sass and css-modules and want to restyle some base component without changing its code. (base component already use css-modules and exposes styles property)

I know two way how to do it.

  1. Using composes css-modules operator. Just extend classes you need, then in javascript code combine both styles as {...baseStyle, ...myStyleSimple}
@sadikovi
sadikovi / LRUCache.scala
Created September 27, 2016 08:59
LRU cache using linked list (super-hacky implementation)
import java.util.HashMap
class Node[K, V](var key: K, var value: V) {
var next: Node[K, V] = null
override def toString(): String = s"Node($key, $value) -> $next"
}
class LRUCache[K, V](val size: Int = 5) {
require(size > 0, s"Expected size > 0, found $size")
val map = new HashMap[K, Node[K, V]]()
@tmpvar
tmpvar / chainhull.js
Created March 3, 2014 21:26
chainHull_2D(): Andrew's monotone chain 2D convex hull algorithm
var isLeft = function(p1, p2, p3) {
return (p2.position[0] - p1.position[0])*(p3.position[1] - p1.position[1]) - (p3.position[0] - p1.position[0])*(p2.position[1] - p1.position[1]);
};
// chainHull_2D(): Andrew's monotone chain 2D convex hull algorithm
// see: http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
// Input: P[] = an array of 2D points
// presorted by increasing x- and y-coordinates
// n = the number of points in P[]
// Output: H[] = an array of the convex hull vertices (max is n)