Skip to content

Instantly share code, notes, and snippets.

@nulayuhz
nulayuhz / allow only number and decimal in input[type=text]
Created May 1, 2015 15:33
allow only number and decimal in input[type=text], comma separate on blur, convert comma separate on focus
//set number to zero if it's null or empty for number field.
function numberFieldChangedEvent(field, fieldName, model, invalid) {
field = field.replace(/[^(0-9.)]/g, ''); //allow only numbers and dots
model[fieldName] = field;
}
function commaSeparateNum(field, fieldName, model) {
// remove extra dots
var tempString = field.toString();
if (tempString.indexOf('.') !== -1) {
// Reset Zoom
self.resetZoom = function() {
var objects = canvas.getObjects();
for (var i in objects) {
var scaleX = objects[i].scaleX;
var scaleY = objects[i].scaleY;
var left = objects[i].left;
var top = objects[i].top;
@nulayuhz
nulayuhz / function declaration vs function expression
Created January 27, 2015 03:00
function declaration vs function expression
function expression:
foo() //try to call foo TypeError!
var foo = function () {
// do something
};
is more like:
var foo;
foo() //try to call foo TypeError!
@nulayuhz
nulayuhz / Lexical Scope
Created January 23, 2015 21:29
Lexical Scope
"lexical scope is based on where variables and blocks of scope are authored, by you, at write time, and thus is (mostly) set in stone by the time the lexer processes your code."
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch2.md#lex-time

This is nice to have when you're working on a .Net project that runs inside of a Parallels/VirtualBox VM. Even more important if you are building a mobile site which needs to run on an iPhone. The iPhone emulator does not run in Windows, so during development it is useful to have the Visual Studio server visible to the host operating system.

These instructions were found over here on StackOverflow.

Use Fiddler 2 as a Reverse Proxy to listen on any port (8080 or 8888) and forward those requests to Visual Studio's built-in web server.

Follow the Fiddler setup instructions. The only tricky part here is to use regedit to set a new registry key, a new DWORD named ReverseProxyForPort inside HKEYCURRENTUSER\SOFTWARE\Microsoft\Fiddler2. In this case we set the value to 3480, which is the default server port in Visual S

@nulayuhz
nulayuhz / Get Array of 10 Years
Last active August 29, 2015 14:11
Get Array of 10 Years
var year = new Date().getFullYear();
var tenYears = [];
for (var i = 0; i < 10; i++) {
tenYears.push(year++);
}
console.log(tenYears);
@nulayuhz
nulayuhz / closure cont
Created December 9, 2014 22:29
closure cont'
function foo() {
var a = 2;
function bar() {
console.log( a );
}
return bar;
}
@nulayuhz
nulayuhz / closure
Created December 9, 2014 21:32
closure
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch5.md
Closure is when a function is able to remember and access its lexical scope even
when that function is executing outside its lexical scope.
function foo() {
var a = 2;
function bar() {
console.log( a ); // 2
@nulayuhz
nulayuhz / hoisting (Function declarations before Variable declarations)
Created December 9, 2014 20:40
hoisting (Function declarations before Variable declarations)
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch4.md#functions-first
@nulayuhz
nulayuhz / hoisting
Created December 9, 2014 20:37
hoisting
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20&%20closures/ch4.md
"When you see var a = 2;, you probably think of that as one statement.
But JavaScript actually thinks of it as two statements: var a; and a = 2;.
The first statement, the declaration, is processed during the compilation phase.
The second statement, the assignment, is left in place for the execution phase."
- declaration comes before the assignment
- function declarations are hoisted, but function expression are not