Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Thiago Dantas tdantas

🏠
Working from home
View GitHub Profile
View admin.js
//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 / queue-function.js
Created Feb 3, 2016
delaying the execution of your function until ready be called
View queue-function.js
const _ = require('lodash');
module.exports = queue;
function queue(fn) {
var queuedArgs = [];
var ready = false;
queuedFn.ready = function() {
ready = true;
View tiny Promise.js
// (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 / monit.rc
Last active Dec 23, 2015
Monitoring with monit recipes
View monit.rc
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"
@tdantas
tdantas / purerb.rb
Created Sep 7, 2013
Using Pure ERB
View purerb.rb
require 'erb'
class ERBPrivateClass
def self.build
new('Joao', 'Almeida')
end
attr_accessor :first_name, :last_name
def initialize(first, last)
View yaml_custom_datatype_object.rb
#!/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 / yaml_ruby_new_lines.rb
Created Aug 31, 2013
YAML preserving new lines
View yaml_ruby_new_lines.rb
#!/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_ruby_datatypes.rb
Last active Dec 22, 2015
YAML Ruby Data Types
View yaml_ruby_datatypes.rb
#!/usr/bin/env ruby
%w(yaml ap).each { |dep| require dep }
obj = YAML::load(DATA)
ap obj
__END__
boolean_true: Yes
boolean_false: No
@tdantas
tdantas / yaml_list.rb
Last active Dec 22, 2015
YAML Ruby List
View yaml_list.rb
#!/usr/bin/env ruby
%w(yaml ap).each { |dep| require dep }
obj = YAML::load(DATA)
ap obj['countries']
puts "-"*20
ap obj['cities']
__END__
View yaml_references.rb
#!/usr/bin/env ruby
%w(yaml ap).each { |dep| require dep }
obj = YAML::load(DATA)
ap obj['test']['host']
__END__
development: &dev
host: localhost
user: username