Skip to content

Instantly share code, notes, and snippets.

@oriSomething
oriSomething / is-old-browser.js
Created February 4, 2015 19:41
Detect old browsers (IE 8-, Android 2.x). The easy way
var isBrowserOld = ! Function.prototype.bind;
// Can also add an CSS class
document.documentElement.className += ' old-browser';
@oriSomething
oriSomething / promise-support-for-template.js
Last active August 29, 2015 14:17
use promises for template's data in Express.js
import _ from 'lodash';
function makeStatic(data) {
return Promise.all(_.map(data, function map(v, k) {
if (v instanceof Promise) {
return v.then(x => x, () => null)
.then(data => [k, data]);
}
return [k, v];
@oriSomething
oriSomething / enum-builder.js
Last active February 24, 2019 08:08
build enums with lodash
import _ from 'lodash';
export function enumNumber(... params) {
return Object.freeze(_.mapValues(_.invert(params), Number));
}
export function enumString(... params) {
return Object.freeze(_.mapKeys(params));
}
@oriSomething
oriSomething / some-component.js
Last active April 3, 2020 09:45
Reflux + React + ES7 decorators
import React, { Component } from 'react';
import storeDecorator from './store-decorator';
import someStore, { SOME_STORE_SYMBOL } from './some-reflux-store';
@storeDecorator(someStore)
class SomeComponent extends Component {
render() {
return (
<div>
{this.state[SOME_STORE_SYMBOL].someProperty}
import Ember from 'ember';
var volatileValue = 0;
export default Ember.Controller.extend({
init() {
this._super(...arguments);
Ember.run.later(this, function interval() {
this.incrementProperty("timer");
console.log(this.get("value"));
@oriSomething
oriSomething / dynamic-component.hbs
Last active August 21, 2016 18:45
Inject Ember.Component dynamicly
{{component componentName args=componentAttributes}}
@oriSomething
oriSomething / demo.js
Last active October 12, 2016 18:51
Mini-CycleJS with RxJS
import Rx from "rxjs/Rx";
import cycleRun from "./mini-cycle";
function loggerDriver(source$) {
source$.subscribe((text) => console.log(text));
return Rx.Observable.empty();
}
@oriSomething
oriSomething / noop.js
Created January 26, 2017 12:04
More dynamic NOOP
var nicerNoop = new Proxy(function() {}, {
get() {
return nicerNoop;
},
apply() {
return nicerNoop;
},
construct() {
@oriSomething
oriSomething / makeRafDelayed.js
Last active April 30, 2017 20:14
Make a React Component that render delayed after requestAnimationFrame event
import React, { Component as ReactComponent} from "react";
export function makeRafDelayed(Component) {
return class RafDelayedComponent extends ReactComponent {
state = {
isFirstRender: true,
};
componentDidMount() {
this.setState({
@oriSomething
oriSomething / file.ts
Created July 17, 2017 16:23
TypeScript tricks
// Source #1: http://ideasintosoftware.com/typescript-advanced-tricks/
// Source #2: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-308052919
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]};
// Example: type TCleanedUser = Omit<IUser, 'privateField1' | 'privateField2'>;