Skip to content

Instantly share code, notes, and snippets.

View weslleyaraujo's full-sized avatar
💤

Weslley Araujo weslleyaraujo

💤
View GitHub Profile
function gi() {
rm .gitignore;
(curl http://www.gitignore.io/api/$@) >> .gitignore;
}
@weslleyaraujo
weslleyaraujo / module.js
Created September 22, 2014 22:23
Module pattern for class
;(function (root) {
var defaults = {
defaultValue: 'thats a default value'
};
// constructor class
function ClassName (options) {
this.options = $.extend(defaults, options);
console.log('im the constructor');
@weslleyaraujo
weslleyaraujo / template.html
Created September 24, 2014 19:09
Simple Javascript Templating by John Resig
<script type="text/html" id="item_tmpl">
<div id="<%=id%>" class="<%=(i % 2 == 1 ? " even" : "")%>">
<div class="grid_1 alpha right">
<img class="righted" src="<%=profile_image_url%>"/>
</div>
<div class="grid_6 omega contents">
<p><b><a href="/<%=from_user%>"><%=from_user%></a>:</b> <%=text%></p>
</div>
</div>
</script>
function TypeOf () {
return Object.prototype.toString.call(this)
.replace(/(\bobject\b\s)/g, '')
.replace(/\[/g, '')
.replace(/\]/g, '')
.toLowerCase();
};
console.log(TypeOf.call({})); // object
console.log(TypeOf.call([])) // array
@weslleyaraujo
weslleyaraujo / extend.js
Created October 4, 2014 18:46
Merge objects
Object.defineProperty(Object.prototype, 'extend', {
enumerable: false,
value: function (from) {
var props = Object.getOwnPropertyNames(from),
dest = this;
props.forEach(function(name) {
var destination;
if (name in dest) {
@weslleyaraujo
weslleyaraujo / git-lg.sh
Created October 15, 2014 22:46
Pretty beauty git lg
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
/**
* @method: PubSub
* */
;(function(global) {
'use strict';
function PubSub () {
this.topics = {};
};
@weslleyaraujo
weslleyaraujo / ArrayUnique.js
Created November 10, 2014 16:03
Unique method for Array in Javascript
Array.prototype.unique = function () {
var cached = [];
return this.filter(function (index) {
if (cached.indexOf(index) === -1) {
cached.push(index);
return index;
}
}.bind(this));
};
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"