Skip to content

Instantly share code, notes, and snippets.

View anasnakawa's full-sized avatar
💭
I may be slow to respond.

Anas Nakawa anasnakawa

💭
I may be slow to respond.
View GitHub Profile
@anasnakawa
anasnakawa / query-string-parse.js
Created April 1, 2014 17:38
easy parsing for both query strings & hash into a casted object literal
/**
* parse given query string url, and return it as
* object literal with proper type casting for primitives
*
* @param {string} url
* @return {object} queryString
*
* notes:
* - requires jQuery for linear typecasting
* - parameter names are all lowercased
@anasnakawa
anasnakawa / native-string-templates.js
Last active August 29, 2015 13:58
because i don't like string concatination
/**
* string parser with data passed as arguments
*
* @param {arguments}
* @return {string}
*
* example:
* --------
* 'i used both [0] & [1], however [1] looks good so far'.parse( 'iphone', 'andoird' ); // "i used both iphone & andoird, however andoird looks good so far"
* 'the weather now in [0] seems to be [1]'.parse( 'Dubai', function() { return 'very hot'; }); // "the weather now in Dubai seems to be very hot"
@anasnakawa
anasnakawa / constant.js
Last active August 29, 2015 14:00
mocking constant behaviour using `Object.defineProperty`, works on real browsers & IE9+
/**
* simulating constant behaviour where
* given value cannot be changed
*
* @param {object} target object where the constant will be defined
* @param {string} key
* @param {object} value
* @return {object} constant
*
* example
function Car() {
this.array = [];
this.log = function() {}
}
Car.prototype.something = function() {
var self = this; // <- fine
this.array.forEach( function(item) {
self.log( item );
});
@anasnakawa
anasnakawa / sass-charset-node.js
Last active August 29, 2015 14:05
adding `charset "utf-8"` to all sass files in the current directory
/**
* node js module to add `@charset "utf-8"` to all
* sass files in the current directory
* -----------------------------------
* sovles this bug:
* https://github.com/sass/sass/issues/1037
* https://github.com/Compass/compass/issues/205
*/
var fs = require( 'fs' );
/**
* polyfilling console.time & timeEnd
* on IE
*/
(function( console ) {
// cache to hold running timers
console._timers = {};
@anasnakawa
anasnakawa / SassMeister-input.scss
Created April 1, 2015 14:27
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
// rtl variables
$bi-app-left : right;
$bi-app-right : left;
$bi-app-direction : rtl;
$bi-app-invert-direction: ltr;
@anasnakawa
anasnakawa / isRtl.js
Last active August 29, 2015 14:20
detect html document if it has right-to-left layout, even if direction is provided using css and not as an attribute.
/**
* polyfill `getComputedStyle` in IE
*/
window.getComputedStyle = window.getComputedStyle || function( element ) {
return element.currentStyle;
}
/**
* detect RTL layout
/**
* knockout observable subscriber that will get triggered only once at most
*
* @param {fn} handler
* @param {object} [optional] context
*/
ko.observable.fn.subscribeOnce = function( handler, context ) {
var subscribtion = this.subscribe(function() {
handler.apply( this, arguments );
@anasnakawa
anasnakawa / inline-image.scss
Created October 16, 2012 17:15
Base64 inline images function using compass/sass
.some-selector {
background: white #{inline_image("image.png")}
}