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
(ifconfig wlan 2>/dev/null || ifconfig en0) | grep inet | grep -v inet6 | awk '{print $2}' | sed 's/addr://g'
# 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))
$.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á'],
@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"...]
@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
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
require 'rbconfig'
def os
@os ||= (
host_os = RbConfig::CONFIG['host_os']
case host_os
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
:windows
when /darwin|mac os/
:macosx
class Person
def self.new(name)
@cache ||= {}
@cache[name] ||= super(name)
end
def initialize(name)
@name = name
end
end
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
function shuffle(o){
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};