Skip to content

Instantly share code, notes, and snippets.

/**
* Created by JetBrains PhpStorm.
* User: adyshev
* Date: 06.04.11
* Time: 12:58
*/
var globalVar = null;
var StrongCookies = jQuery.Class.create({
@smalljam
smalljam / multiModelExample.js
Created April 21, 2011 13:01
Backbone multimodel proof of concept
// make sure underscore.js & backbone.js included above
$ = {ajax: function(){
console.log('BAM!');
console.dir(arguments);
}}
var BaseModel = Backbone.Model.extend({
url: 'whatever',
save: function(attributes, options){
// (obj, ['a', 'b', {'c':'b'}, 'e', 'f']) > {a:,b:,c:,e:,f:}
function mapper (obj, fields) {
var newObj = {};
for(var i = 0, cnt = fields.length; i<cnt; i++) {
var f = fields[i];
if(typeof f == 'string') {
newObj[f] = obj[f]
} else {
for(var k in f) {
newObj[k] = obj[ f[k] ];
@smalljam
smalljam / static_server.js
Created July 25, 2011 17:32 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
// http://jsfiddle.net/Exyk5/
function decode(text){
var lat='`~!@#$%^&qwertyuiop[]asdfghjkl;\'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?',
cyr='ёЁ!"№;%:?йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ/ЯЧСМИТЬБЮ,',
from = cyr,
to = lat,
newtext = '';
if( /[a-zA-Z]{2}/.test(text) ) {
@smalljam
smalljam / gist:1321884
Created October 28, 2011 08:41
Frontend engineering training course
// LECTURES
Frontend engineering introduction (2 x 1 hour)
- web development is
- history
- current situation
- languages and platforms
- FE definition
- Job specific
- knowledge areas
@smalljam
smalljam / dashboard
Created December 15, 2011 03:26
pages overview //TODO: improve
<style type="text/css">
body {
width: 200%;
height: 200%;
}
iframe {
-webkit-transform: scale(0.2);
-webkit-transform-origin: 0 0;
position: absolute;
width: 100%;
@smalljam
smalljam / Exceptions.js
Created December 17, 2011 14:35
Custom exceptions generator
(function(ns){
function createException(name) {
ns[name] = function(text) {
var r = Error.call(this, text);
r.name = name;
return r;
};
}
@smalljam
smalljam / assertInterface.js
Created December 18, 2011 16:41
jsTestDriver assertions
function assertInterface(keys, _interface) {
keys.forEach(function(key){
assertFunction(_interface[key]);
});
}
function assertStrictInterface(keys, _interface) {
assertEquals(keys, Object.keys(_interface));
assertInterface(keys, _interface);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<script>
//https://raw.github.com/dankogai/js-base64/master/base64.js
(function(a){"use strict";var b;typeof module!="undefined"&&module.exports&&(b=require("buffer").Buffer);var c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=function(a){for(var b={},c=0,d=a.length;d>c;c++)b[a.charAt(c)]=c;return b}(c),e=String.fromCharCode,f=function(a){var b=a.charCodeAt(0);return 128>b?a:2048>b?e(192|b>>>6)+e(128|b&63):e(224|b>>>12&15)+e(128|b>>>6&63)+e(128|b&63)},g=function(a){return a.replace(/[^\x00-\x7F]/g,f)},h=function(a){var b=[0,2,1][a.length%3],d=a.charCodeAt(0)<<16|(a.length>1?a.charCodeAt(1):0)<<8|(a.length>2?a.charCodeAt(2):0),e=[c.charAt(d>>>18),c.charAt(d>>>12&63),b>=2?"=":c.charAt(d>>>6&63),b>=1?"=":c.charAt(d&63)];return e.join("")},i=a.btoa||function(a){return a.replace(/[\s\S]{1,3}/g,h)},j=b?function(a){return new b(a).toString("base64")}:function(a){return i(g(a))},k=function(a,b){return b?j(a).replace(/[+\/]/g,function(