Skip to content

Instantly share code, notes, and snippets.

View codemilli's full-sized avatar
😇
Hooked on React Hooks

codemilli codemilli

😇
Hooked on React Hooks
View GitHub Profile
def factorial(number: Int) : Int = {
def factorialWithAccumulator(accumulator: Int, number: Int) : Int = {
if (number == 1)
return accumulator
else
factorialWithAccumulator(accumulator * number, number - 1)
}
factorialWithAccumulator(1, number)
}
println(factorial(5))
@codemilli
codemilli / functor-02.js
Created March 5, 2017 07:41
FunctorObject
class FunctorObject {
constructor (obj) {
this.value = obj;
}
map (func) {
const obj = {};
for (const key of Object.keys(this.value)) {
obj[key] = func(this.value[key]);
}
@codemilli
codemilli / functor-01.js
Created March 5, 2017 07:25
mappable functor
var arr = [ 1, 2, 3, 4 ];
var newArr = arr.map(x => x * 10);
console.log('arr => ', arr);
console.log('newArr => ', newArr);
@codemilli
codemilli / hacky-scrollbar-resize-listener.js
Created February 23, 2017 08:36 — forked from OrganicPanda/hacky-scrollbar-resize-listener.js
A sham that will throw a window resize event even when scrollbars are added/removed (this is not something the standard window resize event does). Tested in IE9+, Chrome & Firefox latest.
// Demo: http://jsfiddle.net/pFaSx/
// Create an invisible iframe
var iframe = document.createElement('iframe');
iframe.id = "hacky-scrollbar-resize-listener";
iframe.style.cssText = 'height: 0; background-color: transparent; margin: 0; padding: 0; overflow: hidden; border-width: 0; position: absolute; width: 100%;';
// Register our event when the iframe loads
iframe.onload = function() {
// The trick here is that because this iframe has 100% width
@codemilli
codemilli / js-style-load.md
Last active February 23, 2017 11:44
style load with javascript

Inline CSS

// function scope for moduling
!function() {
  var style = document.createElement('style');
  
  style.innerText = '::-webkit-scrollbar { width: 8px; }';
  document.getElementsByTagName('head')[0].appendChild(style);
//Below is a JavaScript snippet that parses the response and returns the parameters to the server.
// First, parse the query string
var params = {}, queryString = location.hash.substring(1),
regex = /([^&=]+)=([^&]*)/g, m;
while (m = regex.exec(queryString)) {
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
// And send the token over to the server
import { Component } from '@angular/core';
@Component({
selector: 'sth',
template: `<h2> Hello {{ title }} </h2>`
})
export class TemplateTestComponent {
title: string = " Something ";
}
import { Injectable } from '@angular/core';
@Injectable()
export class ValueConfig {
title: string;
getTitle(): string {
return this.title;
}
}
@import { Injectable, Component } from '@angular/core';
@Injectable()
export class AService {
// ...
}
@Component({
// ...
providers: [ AService ]
package com.features;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import android.util.Log;