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
@millermedeiros
millermedeiros / updateLibs.sh
Last active October 11, 2015 12:37
Shell script to update 3rd party libs
#!/bin/sh
# This shell script is used to bootstrap the app and update external libraries
#
# ====== IMPORTANT ======
#
# it may break application if 3rd party libs aren't backwards compatible
# or if libs were edited locally, use with care !!!
@rotespferd
rotespferd / grunt.js
Created November 24, 2012 15:56
A basic template gruntconfig file for grunt.js
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: '<json:package.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
@anasnakawa
anasnakawa / tiny-template.js
Last active October 13, 2015 07:18
parse a given template and repalce any variables wrapped withing brackets
// parse a given template and repalce any variables wrapped with brackets '{' & '}' with the
// corresponding object found in the passed context param
// * **param:** {string} template sting template to be parsed
// * **param:** {object} context object containing variables to inject into the template
//
// e.g: parse( 'hello my name is {name}, I am a {title}', {
// name: 'Anas Nakawa'
// title: function() {
// return 'software developer'
// }
@rosskevin
rosskevin / Rakefile
Last active October 28, 2015 10:41
Rakefile - less to sass a.k.a. less2sass or less2scss
# less to scss based on http://stackoverflow.com/a/19167099/2363935
namespace :convert do
task :less_to_scss do
source_glob = "assets/less/*.less"
dest_dir = "converted"
rm_r dest_dir rescue nil
mkdir_p(dest_dir)
@luissquall
luissquall / Gruntfile.js
Last active December 16, 2015 08:48
Apply tasks only to changed files.
/*global module:false*/
module.exports = function(grunt) {
// Load tasks
grunt.loadTasks('util/grunt');
// Load vendors tasks
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
@anasnakawa
anasnakawa / media-query.scss
Last active December 19, 2015 08:29
generic media query mixin
// ------------------------------
// generic media query mixin
// ------------------------------
// author: Anas Nakawa
// license: MIT
// ------------------------------
// table of content
// ------------------------------
// media-compact-retina (private)
// media-conpact-normal (private)
@anasnakawa
anasnakawa / coffeescript-extend.js
Last active December 22, 2015 05:18
OOP in javascript extracted from CoffeeScript
// tiny JavaScript inheritance
// extracted from CoffeeScript
//
// * **param:** {Class} child
// * **param:** {Class} parent
var extends = function( child, parent ) {
for ( var key in parent ) {
if ( {}.hasOwnProperty.call( parent, key ) ) {
child[ key ] = parent[ key ];
}