This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ifconfig wlan 2>/dev/null || ifconfig en0) | grep inet | grep -v inet6 | awk '{print $2}' | sed 's/addr://g' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.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á'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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"...] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| def self.new(name) | |
| @cache ||= {} | |
| @cache[name] ||= super(name) | |
| end | |
| def initialize(name) | |
| @name = name | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }; |