Skip to content

Instantly share code, notes, and snippets.

View darlanalves's full-sized avatar
🏠
Writing some code when I'm not busy writing code

Darlan Alves darlanalves

🏠
Writing some code when I'm not busy writing code
View GitHub Profile
/*
* Exemplo:
* var users = [
* {name: 'Victor Queiroz'},
* {name: 'João Bosco'},
* {name: 'Ruan Jordão'}
* ];
*
* Aplicando o filtro:
* {{ users | pluck:'name' | join:', ' }}
(function() {
function only(propertiesToKeep){
var object = this;
if (object === window) return object;
Object.keys(object).forEach(function(key) {
if (propertiesToKeep.indexOf(key) === -1) delete object[key];
});
var gulp = require('gulp'),
concat = require('gulp-concat'),
wrap = require('gulp-wrap'),
multipipe = require('multipipe'),
spaceRe = /\s+/g,
wrapper = '(function(undefined){\n\n<%= contents %>\n}());';
module.exports = function buildModule(src, dest, watch) {
var name = String(src).replace(spaceRe, '-');
@darlanalves
darlanalves / bindonce.js
Created August 5, 2014 04:25
A naive implementation of ng-bindonce
angular.module('ng').directive('ngBindonce', function() {
return function bindOnce($scope, $element, $attrs) {
var removeWatcher = $scope.$watch($attrs.ngBindOnce, function(value) {
if (value === undefined) return;
$element.text(value);
removeWatcher();
});
};
});
angular.module('isValid')
.directive('isValid', function() {
return {
link: linker,
require: '^form'
};
function linker($scope, $element, $attrs, form) {
var expression = $attrs.isValid,
name = $attrs.error;
@darlanalves
darlanalves / inherits.js
Last active August 29, 2015 14:14
Inheritance helper
/**
* @param {Function} NewClass
* @param {Function} SuperClass
*
* @example
* function Foo() {}
* function Bar() { Foo.call(this); }
* inherits(Bar, Foo);
*/
var inherits = function (NewClass, SuperClass, attributes) {
@darlanalves
darlanalves / autogrow.js
Created March 18, 2015 00:50
Autogrow directive for textarea
$module.directive('autogrow', autogrowDirective);
/**
* @directive autogrow
*/
function autogrowDirective() {
return {
link: linker,
require: '?ngModel'
};
@darlanalves
darlanalves / latency.markdown
Created October 12, 2015 01:57 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@darlanalves
darlanalves / spabs.md
Created November 8, 2015 03:44 — forked from eevee/spabs.md
tabs to spaces

Death to tabs, long live spaces

Do this

  1. Fix any inconsistent indentation in your existing files, or Python code will break, since it considers a tab to be 8 and we're about to make it 4.

  2. Populate .gitattributes in your repository, as below.

     *.py filter=spabs
    
@darlanalves
darlanalves / Model.js
Last active January 19, 2016 06:40
New syntax for Gisele models + ES6
import { Model } from Gisele;
const fields = {
name: String
};
export class User extends Model.new(fields) {
modelMethod() {
// ...
}