Skip to content

Instantly share code, notes, and snippets.

View ultim8k's full-sized avatar
🛠️
Rock & roll!

Kostas Kapenekakis ultim8k

🛠️
Rock & roll!
View GitHub Profile
@ultim8k
ultim8k / loop.js
Created June 14, 2013 22:24
A faster javascript loop
/**
* A faster javascript loop
*/
var fruits = ['orange', 'apple', 'banana', 'pear', 'peach', 'cherry'];
var i = fruits.length;
while(i--) {
console.log(fruits[i]);
}
@ultim8k
ultim8k / Asynchronous_functions_in_Javascript.md
Last active June 17, 2018 22:19
Asynchronous functions in Javascript

Asynchronous functions in Javascript

The problem

Some times we want to get data from a function that isn't ready on time, and it's response is delayed. Those functions are called Asynchronous.

var profile = $.get('http://graph.facebook.com/kapenekos',
	function(response){
		console.log(response)
		return response
	})
@ultim8k
ultim8k / conditionall_set.js
Last active December 18, 2015 18:10
Set value of a var based on condition (the lazy way)
/**
* Set value of a var based on condition
*/
var enabled = (true) ? "YES" : "NO" // YES
var status = (enabled == "YES") ? "ENABLED" : "DISABLED" // ENABLED
@ultim8k
ultim8k / short_circuit.js
Created June 26, 2013 14:11
Short-circuit evaluation (AKA lazy assignment)
/**
* Short-circuit evaluation AKA lazy assignment
*/
var a;
var b = null;
var c = undefined;
var d = 4;
var e = 'five';
var f = a || b || c || d || e;
@ultim8k
ultim8k / app-sf.js
Created July 15, 2013 14:33
A front-end app scaffold
/**
* app template
*/
var app = {}
app.settings = {
init_msg : "Thanks Kostas.\nYou are awesome!"
}
app.consolefix = function(){
var self = this

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@ultim8k
ultim8k / dabblet.css
Created August 6, 2013 11:33
Responsive score table
/**
* Responsive score table
*/
.clearfix:before,
.clearfix:after { content: " "; display: table; }
.clearfix:after { clear: both; }
* { box-sizing: border-box; }
@ultim8k
ultim8k / getTotalWidth.js
Created January 11, 2014 11:43
Get total width of a dom element (width + padding + margin + borders)
function getTotalWidth(el){
var width = el.width();
var padding = parseInt(el.css("padding-left"), 10) + parseInt(el.css("padding-right"), 10);
var margin = parseInt(el.css("margin-left"), 10) + parseInt(el.css("margin-right"), 10);
var border = parseInt(el.css("borderLeftWidth"), 10) + parseInt(el.css("borderRightWidth"), 10);
return width + padding + margin + border;
}
@ultim8k
ultim8k / mozilla_bind.js
Created January 23, 2014 11:26
Mozilla Developer Network Bind
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
@ultim8k
ultim8k / jquery_plugin_callback.md
Last active February 7, 2019 08:27
Adding a callback handler to a jQuery plugin

Adding a callback handler to a jQuery plugin

(function($){
	$.fn.myAwesomePlugin = function(settings) {
		var callback = settings.callback;
		if ($.isFunction(callback)) {
			var parameter = 'Hello World';
			callback.call(this, parameter);
 }