Skip to content

Instantly share code, notes, and snippets.

View edymerchk's full-sized avatar
:shipit:
Shipping

Edy Laverde edymerchk

:shipit:
Shipping
  • Medellin
View GitHub Profile
fibbonacci = Hash.new do |accumulator, index|
accumulator[index] = fibbonacci[index - 2] + fibbonacci[index - 1]
end.update(0 => 0, 1 => 1)
irb(main)> fibbonacci[100]
=> 354224848179261915075
@edymerchk
edymerchk / look_up_methods_order.rb
Created August 22, 2014 22:02
demonstration of order that ruby methods are look up
module W
def foo
"- Mixed in method defined by W\n" + super
end
end
module X
def foo
"- Mixed in method defined by X\n" + super
end
@edymerchk
edymerchk / order.rb
Last active August 29, 2015 14:05
order strings like numbers
# Say you have a string field in the DB that needs to be order like numbers
#If you do the following... maybe its not what you want:
Document.order(:number).pluck(:number)
=> [ "1", "10591059616", "100", "2", "22"....]
# But if you do...:
Document.order("LENGTH(documents.number), number").pluck(:number)
=> ["1", "2", "22", "99", "100", "10591059616"...]
$.datepicker.regional['es'] = {
closeText: 'Cerrar',
prevText: '<Ant',
nextText: 'Sig>',
currentText: 'Hoy',
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
# based on Haversine formula
# http://en.wikipedia.org/wiki/Haversine_formula
distance = (lat1, lon1, lat2, lon2) ->
R = 6371
a = 0.5 - Math.cos((lat2 - lat1) * Math.PI / 180) / 2 + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * (1 - Math.cos((lon2 - lon1) * Math.PI / 180)) / 2
R * 2 * Math.asin(Math.sqrt(a))
(ifconfig wlan 2>/dev/null || ifconfig en0) | grep inet | grep -v inet6 | awk '{print $2}' | sed 's/addr://g'
@edymerchk
edymerchk / page-break.sass
Created December 11, 2014 19:13
page-break for pdf
.page-break
display: block
clear: both
page-break-after: always
@edymerchk
edymerchk / external_ip.sh
Last active August 29, 2015 14:13
Get External IP Address
#1. Using lynx
brew install lynx
lynx --dump http://ipecho.net/plain
#2. Using curl
curl http://ipecho.net/plain
du -sh `rbenv root`/versions/*
@edymerchk
edymerchk / active_admin.js.coffee
Last active December 2, 2015 13:15
active_admin custom js page scope
# app/assets/javascripts/active_admin.js.coffee
#= require active_admin/base
ActiveAdmin = {
dashboard: {},
user: {}
}
ActiveAdmin.dashboard.index = () ->
console.log 'Hello'