Skip to content

Instantly share code, notes, and snippets.

View fakenickels's full-sized avatar
💭
hello this is a mic test, are you listening

Gabriel fakenickels

💭
hello this is a mic test, are you listening
View GitHub Profile
@fakenickels
fakenickels / swap.js
Created April 26, 2014 16:53
Swap macro with Sweet.js
macro swap {
rule { $x and $y } => {
var tmp = $x;
$x = $y;
$y = tmp
}
}
// Let's go!
var a = "a",
@fakenickels
fakenickels / isNull.js
Created May 3, 2014 16:27
Gist for Medium post
function isNull( str ){
return str === null ? true : false;
}
@fakenickels
fakenickels / tmpl_engine.js
Created June 19, 2014 19:37
The most simple template engine
function tmpl(text, o){
return text.replace(/({(.+)})/gm, function( exp, conj, innerExp ){
return eval(innerExp);
});
}
@fakenickels
fakenickels / security.js
Created July 13, 2015 14:09
ongoworks:security
Security.defineMethod("ifHasUserId", {
fetch: [],
transform: null,
deny: function (type, args, userId, document) {
return userId !== arg;
}
});
@fakenickels
fakenickels / argumentschema.js
Last active August 29, 2015 14:25
Schema for arguments, say goodbye to if's crazyness
ArgumentsSchema = function(args, schema, extra){
var orderedArgs = {};
for(var arg in args){
for(var field in schema){
if(schema.hasOwnProperty(field)){
if(args[arg].constructor === schema[field]){
orderedArgs[field] = args[arg];
}
}
@fakenickels
fakenickels / es2015_meteor_session.js
Created September 27, 2015 00:06
Meteor Session similar in ES2015
SessionHandler = {
_deps: new Tracker.Dependency,
get(target, name){
this._deps.depend();
return target[name];
},
set(target, name, value){
target[name] = value;
this._deps.changed();
// @locus: server
if(Meteor.isServer){
Tracker.autorun(() => {
CollectionObserved.find();
collectAndSaveData();
});
function collectAndSaveData(){
var aggregateData = CollectionObserved.aggregate(...);
var aggregateDocId = ...;
@fakenickels
fakenickels / projectlines.rb
Created September 16, 2012 00:57
Count lines of a project. It scans folder( and subfolders ) files and count total lines
#!/usr/bin/ruby
require 'find'
if ARGV[0]
puts "Wait..."
Find.find( ARGV[0] ) do |f|
totalLength += IO.readlines(f).size if File.file? f
end
end
@fakenickels
fakenickels / matavogais.rb
Created September 18, 2012 16:03
Pega um arquivo de texto, e cria um novo arquivo de texto retirando todas as vogais e trocando-as por -
#!/usr/bin/ruby
# Troca vogais e coloca um hifen no lugar das mesmas
# passe como argumento o arquivo de texto i.e. ->
# matavogais.rb /home/masterboss/vogais.txt
File.open("#{File.dirname(ARGV[0])}/noVogals.txt",'w') do |f|
f << File.read( ARGV[0] ).gsub(/[aeiou]/i, '-')
end
@fakenickels
fakenickels / wordor.rb
Created September 22, 2012 21:02
Organiza arquivos com um nome que contem um mesmo trecho de uma palavra
#!/usr/bin/ruby
# Example: wordor /anything/ ruby
# Found: anythingruby.pdf and rubynotify.rb, after put they in ruby/ folder
require 'find'
require 'fileutils'
if !ARGV.empty?
path = "#{ARGV[0]}/#{ARGV[1]}"
reg = /#{ARGV[1]}/
Dir.mkdir( path,0755 ) unless File.exists? path