Skip to content

Instantly share code, notes, and snippets.

View abiodun0's full-sized avatar

Abiodun abiodun0

View GitHub Profile
@abiodun0
abiodun0 / multipleComponent.js
Last active October 3, 2017 04:39
beauty of ramda
import React from 'react'
import { render } from 'react-dom'
import { compose, map, prop, curry, reduce, pipe } from 'ramda'
const combine = curry((c, o) => x => (<div>{c(x)} {o(x)}</div>))
const combineComponents = (...args) => {
const [first, ...rest] = args
return reduce((acc, c) => combine(acc, c), first, rest)
}
@abiodun0
abiodun0 / inheritance.js
Created October 31, 2016 17:03
Prototypal inheritcan vs parasytical inheritance
const Nuddles = function(clientId, clientSecret) {
this.clientId = clientId
this.clientSecret = clientSecret
}
let myNuddlesObject = new Nuddles("myidkey", "mysecrettoken")
const Venue = function(nuddlesObject, venueId) {
function on (object, eventName, listenerFn) {
object.addEventListener(eventName, listenerFn)
return function unsubscribe () {
object.removeEventListener(eventName, listenerFn)
}
}
on(object, 'eventName', callback);
@abiodun0
abiodun0 / doublefunc.py
Last active December 22, 2016 11:18
Use array destructuring, recursion, and the rest/spread operators to create a function 'double' that will return a new array with all values inside of it multiplied by two. Do not use any array helpers!
def fold(f, init, arr):
return init if len(arr) < 1 else fold(f, f(init, arr[0]), arr[1:])
def map(f, xs):
return fold(lambda acc, v: acc + [f(v)], [], xs)
def multiplyByTwo(x):
def multiplySecond(y):
return x * y
return multiplySecond
@abiodun0
abiodun0 / django.py
Created December 27, 2016 22:23
simplest django app
import sys
from django.conf.urls import url
from django.http import HttpResponse
from django.conf import settings
settings.configure(
DEBUG=True,
SECRET_KEY='thisisthesecretkey',
ROOT_URLCONF=__name__,
@abiodun0
abiodun0 / someComponent.ts
Created December 30, 2016 04:12
avoid Angular 2 http method to fire an ajax everytime a component subscribes to it
export someClass {
private relplay: ReplaySubject<any> = new ReplaySubject<any>(1);
subscribeToReplay(): ReplaySubject<any> {
return this.replay;
}
@abiodun0
abiodun0 / solution.py
Last active January 1, 2017 06:25
Highest population
def most_populated(births, deaths):
b = dict((i, births.count(i)) for i in births)
d = dict((i, deaths.count(i)) for i in deaths)
alive = 0
years = {}
for year in range(min(births), max(deaths)):
alive = alive + b.get(year, 0) - d.get(year, 0)
years[year] = alive
max_year = max(years.values())
return [key for key, val in years.iteritems() if val == max_year]
@abiodun0
abiodun0 / nextedArraysCompose.js
Last active January 13, 2017 06:28
Functional Compose
const map = f => arr => arr.map(f);
const compose = (f, g) => x => f(g(x));
const add = x => y => x + y;
const nestedData = [[1, 2, 3], [4, 5, 6]];
const nestedData2 = [[[1, 2, 3], [4 ,5, 6], [7, 8, 9]], [[1, 2, 3], [4 ,5, 6], [7, 8, 9]], [[1, 2, 3], [4 ,5, 6], [7, 8, 9]]];
@abiodun0
abiodun0 / decorateTimeOut.ts
Last active February 4, 2017 13:05
decorator in it's simplest form for setTimeout (An example of how to abstract common decorators to it's own function)
function timeout( milliseconds: number = 0 ) {
return function( target, key, descriptor ) {
var originalMethod = descriptor.value;
descriptor.value = function (...args) {
setTimeout(() => {
originalMethod.apply(this, args);
@abiodun0
abiodun0 / BaseStore.js
Created February 4, 2017 21:14
Some old ways of implementing flux architecture
import {EventEmitter} from 'events';
import AppDispatcher from '../dispatcher/AppDispatcher';
export default class BaseStore extends EventEmitter {
constructor() {
super();
}
subscribe(actionSubscribe) {
this._dispatchToken = AppDispatcher.register(actionSubscribe());
}