Skip to content

Instantly share code, notes, and snippets.

View gryzzly's full-sized avatar

Misha Reyzlin gryzzly

View GitHub Profile
@gryzzly
gryzzly / Pagination.js
Last active December 9, 2016 09:59
React Pagination (similar to Github’s pagination)
'use strict';
import React, {PropTypes} from 'react';
import classNames from 'classnames';
function last(list) {
return list[list.length - 1];
}
function areAdjacent(prev, curr) {
return last(prev).index + 1 === curr[0].index;
@gryzzly
gryzzly / index.js
Created June 18, 2015 20:02
requirebin sketch
var items = [
{ key: 'mishacloudcom' },
{ key: 'jamescloudcom' },
{ key: '#feedbackcloudcom' },
{ key: '#lalala.comfreenode' },
{ key: '#emberjsfreenode' },
{ key: '#reactjsfreenode' },
{ key: '#devcloud.com' },
{ key: '#ircv3-devcloud.com' },
{ key: '#devfreenode' }
@gryzzly
gryzzly / debounced-input.js
Last active December 15, 2016 21:51
Ember Debounced Input
//
// To be used like this:
//
//
// {{debounced-input
// placeholder="1000000"
// value=propertyName
// debounceWait=300 <-- debounce wait value
// fireAtStart=false <-- corresponds to Ember.run.debounce’s 4th param, if false, will run at the end of wait period
// class="form-control" <-- all regular text input attributes work

Example of a tedious task when using backbone MVC

You have three components each of which might have certain state. These components depend on one particular component that emits events. These three views have to all define the emitting component as a dependency and manually subscribe to the events in order to sync the state.

var View = require('lib/View'),
    source = require('source'); 
    
module.exports = View.extend({
@gryzzly
gryzzly / logical OR vs array::some.md
Last active August 29, 2015 14:01
logical OR vs array::some
return !!(// double negation is required since logical operators dont always return Booleans
  ENV_VAR || 
  SomeLongStore.get('key') ||
  SomeConfig.get('layer', 'sub-layer') === 'required-value' ||
  this.anotherLongCondition()
)

vs

@gryzzly
gryzzly / tabTalk.js
Last active December 23, 2015 01:29
tabTalk
(function(root, mod) {
if (typeof exports == "object" && typeof module == "object") return mod(exports); // CommonJS
if (typeof define == "function" && define.amd) return define(["exports"], mod); // AMD
mod(root.tabTalk || (root.tabTalk = {})); // Plain browser env
})(this, function(exports) {"use strict";
var
win = window
, storage = win.localStorage
, prefix = 'tab_'
, instance = prefix + date.now() // identify this tab
/* global Tyrtle */
// by convention, test files end with `-test`
var tests = Object.keys(window.__karma__.files).filter(RegExp.prototype.test.bind(/-test\.js$/));
window.requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base/public/',
paths: {
'$': 'lib/dollar/dollar',
'backbone': 'vendor/backbone',
@gryzzly
gryzzly / karma-tyrtle.js
Created September 9, 2013 15:57
Karma Runner Tyrtle Adapter
/* global Tyrtle:true */
(function (window) {
/**
* Tyrtle renderer/reporter for Karma
* @param {Object} karma Karma runner instance
*/
function TyrtleKarmaRenderer(karma) {
this.karma = karma;
}
// request default HTML5 widget's code
$.getJSON(
'http://soundcloud.com/oembed' +
'?format=json' +
'&url=http://soundcloud.com/forss/flickermood'
).done(function (embedData) {
console.log(embedData.html);
});
// request Flash widget code
@gryzzly
gryzzly / JavaScript-custom-types-mechanics.js
Last active October 11, 2015 18:38 — forked from sym3tri/JavaScript-new-operator.js
How JavaScript OOP works
// constructor definition
var Foo = function() {
// when invoked with `new` it's as if the following implicitly happens
// this = { constructor: Foo };
// return this;
};
// For every function, `prototype` property is created automatically:
Foo.hasOwnProperty('prototype') // true