This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1: how could you rewrite the following to make it shorter? | |
| if (foo) { | |
| bar.doSomething(el); | |
| } else { | |
| bar.doSomethingElse(el); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function factorial( n ) { | |
| if (n > 1) { | |
| return factorial(n-1) * n; | |
| } else { | |
| return 1; | |
| } | |
| } | |
| console.log( factorial( 1 ) 1 ); | |
| console.log( factorial( 3 ), 6 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tests['backgroundsize'] = function() { | |
| var bool = test_props_all( 'backgroundSize' ); | |
| if (bool){ | |
| bool = new Boolean(bool); | |
| bool.contain = !!(function() { | |
| set_css('background-size: contain'); | |
| return contains(m_style['backgroundSize'], 'contain'); | |
| }); | |
| bool.cover = !!(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var maxThrottles = 10; | |
| connectionManager[connection.id].lastMessage = +new Date(); | |
| connectionManager[connection.id].timeOutUntil = connectionManager[connection.id].lastMessage + 1000; // one second, too long? | |
| connectionManager[connection.id].throttledCount = 0; | |
| connection.addListener("message", function( message ) { | |
| var messageTime = +new Date(); | |
| if (messageTime < connectionManager[connection.id].timeOutUntil) { | |
| (throttleCount < maxThrottles) ? connectionManager[connection.id].throttledCount++ : kickMe(connection.id); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // From @izs /via @janl | |
| // http://twitter.com/izs/status/17744109574 | |
| // JavaScript one-liner to swap two variables: | |
| foo = [bar, bar = foo][0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Flattens the Array produced by .serializeArray() into an Object | |
| // with names as keys and values as their values. | |
| (function($) { | |
| $.fn.serializeObject = function() { | |
| var formData = this.serializeArray(), | |
| data = {}; | |
| for (var i=0, len=formData.length; i<len; i++) { | |
| data[formData[i].name] = formData[i].value; | |
| } | |
| return data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- This is a Node+WebSocket powered demo to sync videos | |
| across different browsers. This file is the client, | |
| the other one is the Node server. Powered by Node and | |
| http://github.com/miksago/node-websocket-server --> | |
| <style> | |
| .inactive { display: none; } | |
| .active { display: block; } | |
| </style> | |
| <script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function ($) { | |
| $.event.special.textchange = { | |
| setup: function (data, namespaces) { | |
| $(this).bind('keyup', $.event.special.textchange.handler); | |
| $(this).bind('cut paste input', $.event.special.textchange.delayedHandler); | |
| }, | |
| teardown: function (namespaces) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // from @rem's Canvas collaborative drawing demo | |
| // http://rem.im/collab-drawing.html | |
| ctx.strokeStyle = '#' + (~~(Math.random() * 16777215)).toString(16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var performance = (function () { | |
| var my = {}; | |
| // Wrap a function body in this to return a copy that instruments itself | |
| // If you want this to be useful, you should give your profiled function a name, | |
| // otherwise it will be identified as "", which is less than useful. | |
| my.profile = function (func) { | |
| return function () { | |
| var start = new Date().getTime(), | |
| time, |