Skip to content

Instantly share code, notes, and snippets.

View mateusvahl's full-sized avatar
🏠
Working from home

Mateus Vahl mateusvahl

🏠
Working from home
View GitHub Profile
"Computer scientists do not know their history...we think everything is new in our field, but in reality, most things are really old, and they are invented or discovered by mathematicians" - Dr. Erik Meijer
@mateusvahl
mateusvahl / HighCotrastJS.js
Created February 26, 2016 19:28
High Cotrast JS
function parseBackground($element) {
var css = $element.css('background-color');
if (!css || (css == 'rgba(0, 0, 0, 0)' || css == 'transparent')) {
return;
}
$element.css('background-color', 'black');
}
function parseColor($element) {
// Logged User can access they feed
var LoggedUser = {
neewsFeed: function() {
console.log('/feed');
// return redirect('/feed')
}
}
// Let's represent the absence of an credential user
// https://en.wikipedia.org/wiki/Null_Object_pattern
(scope "/"
(scope "admin"
(scope "/user"
(get "index" 'index-controller))))
->
(get "/admin/user/index")
@mateusvahl
mateusvahl / Txt
Created June 1, 2016 03:11
Handlebars
Writes a new render engine:
{(yields}} can be implemented with helpers.
{{content_for}} and {{output_for}} can be implemented with helpers and state.
{{docs}} can be implemented with helpers+state+blocks, also use handlebars to output default cars in doc.
{{metadata}} can be implemented with helpers in a before render step.
{{lorem 1000}} writes 1000 lines of lorem ipsum
final step: check for patterns not used
var pattern = name;
var outlet = new Handlebars.SafeString(options.fn(this));
var params = Object.assign(options.hash, {outlet: outlet});
var template = Handlebars.compile(`{{> ${name} }}`);
return template(params);
handlebars.createHelper('>>', function(partial, context) {
var html = handlebars.partials[partial];
delete this.styleModifier
var template = handlebars.compile(html)(Object.assin({}, this, context.hash));
return handlebars.SafeString(template);
});
#!/usr/bin/env ruby
#require "./selector_cleaner/version"
require "nokogiri"
module Selector
# Returns a array of elements that match with the css selector
# Params:
# +selector+:: CSS selector to be found
# +html+:: File to be searched
def self.find(selector, html)
@mateusvahl
mateusvahl / gist:12c7579ed40abe5d2ff0b821b5b2cc01
Created August 21, 2017 02:30
Javascript html structure like hiccup
// http://ramdajs.com/repl/#?const%20parseAttributes%20%3D%20pipe%28%0A%20%20toPairs%2C%0A%20%20map%28%28%5Bkey%2C%20val%5D%29%20%3D%3E%20val%20%3F%20%60%24%7Bkey%7D%3D%22%24%7Bval%7D%22%60%20%3A%20key%29%2C%0A%20%20join%28%27%20%27%29%0A%29%3B%0A%0Aconst%20render%20%3D%20%28%5Btag%2C%20...rest%5D%29%20%3D%3E%20%7B%0A%20%20if%28%21tag%29%20return%3B%0A%20%20%0A%20%20var%20attributes%20%3D%20rest%5B0%5D%3B%0A%20%20var%20body%20%3D%20rest.slice%281%29%3B%0A%20%20%0A%20%20if%28Array.isArray%28attributes%29%20%7C%7C%20is%28String%2C%20attributes%29%29%20%7B%0A%20%20%20%20body%20%3D%20%5Battributes%2C%20...rest.slice%281%29%5D%3B%0A%20%20%20%20attributes%20%3D%20%7B%7D%3B%0A%20%20%20%7D%0A%20%20%20%0A%20const%20attributesRendered%20%3D%20parseAttributes%28attributes%29%3B%0A%20const%20a%20%3D%20attributesRendered%20%3F%20%27%20%27%20%2B%20attributesRendered%20%3A%20%27%27%3B%0A%20const%20b%20%3D%20body.map%28_%20%3D%3E%20is%28String%2C%20_%29%20%3F%20_%20%3A%20render%28_%29%29.join%28%27%27%29%3B%0A%20%20%0A%20ret