Skip to content

Instantly share code, notes, and snippets.

View edinella's full-sized avatar
🐝
“Nothing will work unless you do.” — Maya Angelou

Ezequias Dinella edinella

🐝
“Nothing will work unless you do.” — Maya Angelou
View GitHub Profile
@edinella
edinella / snake-case to camelCase.js
Created November 7, 2013 05:35
Converte snake-case para camelCase
var snakeCaseStr = 'lorem-ipsum';
var camelCaseStr = snakeCaseStr.replace(/(\-\w)/g, function(match){return match[1].toUpperCase();});
// implementation
var Beat = require('beat');
module.exports = function(alias) {
var app = new Beat(alias);
var BeatObject = function BeatObject(callback) {
for(var key in BeatObject)
if(BeatObject.hasOwnProperty(key)) {
var keyParts = key.match(/^(.+)Factory$/);
if(keyParts === null)
app.value(key, BeatObject[key]);
@edinella
edinella / js_to_csv.js
Created October 25, 2013 12:31
JS to CSV
var dados = [
['Nome', 'Sobrenome', 'Profissão'],
['Paula', 'Tejando', 'Adivinha' ],
['Cuca', 'Beludo', 'Padeiro' ],
['Thomas', 'Turbano', 'Popeye' ]
];
var csv = dados.map(function(linha){
return linha.map(function(celula){
return '"'+(celula.replace(/\"/g, '\"').replace(/\r/g, '\\r'))+'"';
// motor
function Motor(hp){
this.hp = hp;
this.rotacoes = 0;
console.log('criou novo motor:', this);
}
Motor.prototype.liga = function(){
this.rotacoes = 2000;
console.log('ligou o motor:', this);
};
@edinella
edinella / requireAt.js
Created September 15, 2013 22:45
Node.js "require" with specific paths array
// obtém pacote nos paths específicos
var requireAt = function requireAt(packageName, paths) {
// armazena paths originais deste ambiente, preservando-os
var originalPaths = module.paths;
// define paths para este ambiente, sobreescrevendo atuais
module.paths = paths;
// obtém modulo nos paths deste beat
.directive('timePicker', function($compile) {
var range = function(qtd) {
var arr = [];
for(var i=0;i<qtd;i++)
arr.push(i<10?'0'+i:''+i);
return arr;
};
var timePickerHoras = range(24);
var timePickerMinutos = range(60);
return {
.directive('popover', ['$compile', function($compile){
return {
restrict: 'E',
link: function ($scope, $element, $attrs) {
var triggerSelector = $attrs.triggerSelector || '[popover-trigger], [data-popover-trigger], [x-popover-trigger], .popover-trigger, .x-popover-trigger';
var elTrigger = $element.find(triggerSelector).first();
var triggerHTML = elTrigger.clone().wrap('<div>').parent().html();
elTrigger.remove();
var triggerElement = $compile(triggerHTML)($scope);
$element.replaceWith(triggerElement);
@edinella
edinella / toDate.directive.js
Created July 9, 2013 20:06
Aplica o filtro 'date' do angular mesmo que a entrada seja uma string
/**
* {{ 'October 13, 1975 11:13:00' | toDate }}
* {{ 'October 13, 1975 11:13:00' | toDate:'yyyy-MM-ddTHH:mm:ss.SSSZ' }}
*/
.filter('toDate', function ($filter) {
return function(input, format) {
format = format || 'medium';
return $filter('date')(new Date(input), format);
};
})
@edinella
edinella / getRemote.directive.js
Created July 3, 2013 01:25
Obtém dados remotos para o escopo local
/*
* <select get-remote="http://path/to/users.json as users">
* <option ng-repeat="user in users" ng-value="user.id">{{user.name}}</option>
* </select>
*/
.directive('getRemote', function ($http) {
return {
restrict: 'A',
link: function ($scope, $element, $attrs) {
var pars = $attrs.getRemote.toLowerCase().split(' as ');
@edinella
edinella / ng-name.directive.js
Last active December 19, 2015 06:58
Diretiva para adicionar campos com name dinâmico ao form, para validação
/*
* https://groups.google.com/forum/?fromgroups=#!topic/angular/suCtNH10M2U
*
* <p ng-repeat="campo in campos">
* <label>{{campo.label}}</label>
* <input ng-name="campo.name" />
* </p>
*
* formName[fieldName].$error.required
*/