Skip to content

Instantly share code, notes, and snippets.

View gryzzly's full-sized avatar

Misha Reyzlin gryzzly

View GitHub Profile
var reverseString = function ( subj ) {
var helper = subj.split (''),
i = 0, k = helper.length, len = helper.length / 2,
swap
for ( ; i < len; i += 1, k -= 1 ) {
swap = helper[ k ];
helper[ k ] = helper[ i ];
helper[ i ] = swap;
}
@gryzzly
gryzzly / gist:1364474
Created November 14, 2011 17:10
renderTemplate from DoAT Touchy, basic JS templating
// Render JavaScript template (from http://git.io/B7KxZg DoAT Touchy)
//
// You can place your template in a script tag with type other than "text/javascript"
// such as "text/html", like this:
// <script type="text/html" id="item-template">
// <li id="{{id}}">
// <p>{{content}}</p>
// </li>
// You'd then render your template like this:
// var itemTemplate = document.getElementById('item-template').innerHTML;
@gryzzly
gryzzly / instanceof vs Object.prototype.toString
Created January 21, 2012 15:18
instanceof vs Object.prototype.toString
!function () {
// helper to set prototype chain up
var Constructor = function () {};
Constructor.prototype = Array.prototype;
var NotRealArray = function () {};
// inherit from Array
NotRealArray.prototype = new Constructor;
@gryzzly
gryzzly / gist:1714086
Created February 1, 2012 00:07
Backbone's extend self-propagating function
// Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and
// class properties to be extended.
var inherits = function(parent, protoProps, staticProps) {
var child;
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
if (protoProps && protoProps.hasOwnProperty('constructor')) {
@gryzzly
gryzzly / naive-bind.js
Created April 4, 2012 14:21
Basic Function.bind
// naïve bind implementation
Function.prototype.bind = function () {
var obj = arguments[0], args = [].slice.call(arguments, 1);
return function () {
this.apply(
obj,
[].concat.call(args, [].slice.call(arguments))
);
}
@gryzzly
gryzzly / testtest.js
Created April 29, 2012 17:04
Testing
function () {}
@gryzzly
gryzzly / backboneView.handleEvent.md
Created May 16, 2012 23:54
Using handleEvent with Backbone

Combining handleEvent and Backbone

I'm sure for most of you it's the old news, but here's a short reminder anyway:

song = {
	handleEvent: function (event) {
    	switch (event.type) {
          case: "click":

console.log(this.name);

@gryzzly
gryzzly / backbone-touch-click.js
Created May 21, 2012 15:41
Backbone touch / click events
var down = "touchup" in window ? "touchup" : "click";
var abstractView = Backbone.View.extend({
// we don't want both click and touch handlers
// delegated on touch-enabled devices
events: function () {
"click .toggler" : "foo",
"touchup .toggler" : "bar"
},
initialize: function () {
@gryzzly
gryzzly / otsbjs.md
Created May 25, 2012 14:29 — forked from janl/otsbjs.md
Open Tech School Berlin JS

In the spirit of Railsgirls Berlin, we want to start a programming education group for JavaScript. We need your help to get all the coaching done.

If you are interested in coaching JavaScript, fork this gist and add yourself or leave your contact data in a comment:

@gryzzly
gryzzly / ycombinator.js
Created May 30, 2012 08:30
fixed point in JavaScript
// An example from http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/
var Y = function (F) {
return (function (x) {
return F(function (y) { return (x(x))(y);});
}(function (x) {
return F(function (y) { return (x(x))(y);});
}));
};