Skip to content

Instantly share code, notes, and snippets.

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

Thiago Dantas tdantas

🏠
Working from home
View GitHub Profile
@tdantas
tdantas / yaml_ruby_new_lines.rb
Created August 31, 2013 14:38
YAML preserving new lines
#!/usr/bin/env ruby
%w(yaml ap).each { |dep| require dep }
obj = YAML::load(DATA)
puts obj['paragraph']
p "-"*30
puts obj['line']
__END__
@tdantas
tdantas / yaml_custom_datatype_object.rb
Created August 31, 2013 15:30
YAML Ruby Custom Data Type
#!/usr/bin/env ruby
%w(yaml ap ostruct).each { |dep| require dep }
class Plans
attr_accessor :name, :price, :recurrence
def initialize(name, price, recurrence)
@name = name
@price = price
@recurrence = recurrence
end
@tdantas
tdantas / purerb.rb
Created September 7, 2013 18:23
Using Pure ERB
require 'erb'
class ERBPrivateClass
def self.build
new('Joao', 'Almeida')
end
attr_accessor :first_name, :last_name
def initialize(first, last)
@tdantas
tdantas / monit.rc
Last active December 23, 2015 04:59
Monitoring with monit recipes
check system localhost
if loadavg (1min) > 8 then alert
if loadavg (5min) > 4 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% for 8 cycles then alert
if cpu usage (system) > 40% for 8 cycles then alert
if cpu usage (wait) > 20% for 8 cycles then alert
check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
// (c) copyright unscriptable.com / John Hann
// License MIT
// For more robust promises, see https://github.com/briancavalier/when.js.
function Promise () {
this._thens = [];
}
Promise.prototype = {
@tdantas
tdantas / queue-function.js
Created February 3, 2016 15:25
delaying the execution of your function until ready be called
const _ = require('lodash');
module.exports = queue;
function queue(fn) {
var queuedArgs = [];
var ready = false;
queuedFn.ready = function() {
ready = true;
//path: plugins/admin.js
const plugin = module.exports;
plugin.register = register;
plugin.register.attributes = {
name: 'admin plugin',
version: '0.0.1-alpha-beta-gama'
};
@tdantas
tdantas / index.js
Last active March 7, 2016 18:33
using npm with gist
module.exports = console.log.bind(console, 'hello world');
@tdantas
tdantas / short.clj
Created April 12, 2016 16:25
shortner
;;adambard
(ns urlshortener.core
(:require
[org.httpkit.server :refer [run-server]]
[taoensso.carmine :as redis])
(:import
clojure.lang.Murmur3
org.apache.commons.validator.routines.UrlValidator))
(def validator (UrlValidator. (into-array ["http" "https"])))
@tdantas
tdantas / angularjs_directive_attribute_explanation.md
Created June 29, 2016 21:28 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>