This file contains 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
// locate this in src/main/scala/ to compile with sbt | |
import org.joda.time.Period | |
import org.joda.time.format.PeriodFormat | |
import org.scala_tools.time.Imports._ | |
object Main extends App { | |
def periodDiff(t1: Period)(t2: Period) = PeriodFormat.getDefault print (t1 - t2).normalizedStandard | |
println( periodDiff(2.hours + 14.minutes + 39.seconds)(1.hour + 32.minutes + 43.seconds) ) |
This file contains 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
\url{http://www.krugosvet.ru/enc/nauka_i_tehnika/astronomiya/CHERNAYA_DIRA.html} | |
ЧЕРНАЯ ДЫРА – область пространства, в которой гравитационное притяжение настолько сильно, что ни вещество, | |
ни излучение не могут эту область покинуть. Для находящихся там тел вторая космическая скорость (скорость убегания) | |
должна была бы превышать скорость света, что невозможно, поскольку ни вещество, ни излучение не могут двигаться быстрее | |
света. Поэтому из черной дыры ничто не может вылететь. Границу области, за которую не выходит свет, называют | |
«горизонтом событий», или просто «горизонтом» черной дыры. | |
\section{История} | |
Основные этапы \url{https://ru.wikipedia.org/wiki/Чёрная_дыра} |
This file contains 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
irb> class B | |
irb> def initialize | |
irb> @a = 1 | |
irb> @b = 2 | |
irb> end | |
irb> end | |
=> nil | |
irb> B.new.to_s | |
=> "#<B:0x4592ca0>" | |
irb> B.new.inspect |
This file contains 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
#include "widget.h" | |
#include "ui_widget.h" | |
#include "qextserialport.h" | |
#include <QInputDialog> | |
namespace { | |
const QString DEFAULT_PORT = "COM6"; | |
} | |
Widget::Widget(QWidget *parent) : |
This file contains 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
// Paste following into the address bar. | |
// simple notepad | |
data:text/html, <html contenteditable> | |
// edit any text on web page | |
javascript:document.getElementsByTagName('html')[0].contentEditable=true; | |
// powerful notepad for Ruby or any other language | |
// https://gist.github.com/4670615 |
This file contains 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
resources :doctors do | |
get 'new_schedule', :on => :member | |
end | |
resources :schedules do | |
get 'new_appointment', :on => :member | |
end | |
resources :appointments | |
# With this /doctors/123/new_schedule will map to DoctorsController#new_schedule | |
# and /schedules/321/new_appointment will map to SchedulesController#new_appointment |
This file contains 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
# First I modify your models a bit: | |
Class Appointment ... | |
# belongs_to :doctor (replace it with this ↓) | |
has_one :doctor, through: :schedule # This means 'doctor_id' is not stored in appointments table, it is got from schedule via join | |
belongs_to :schedule | |
end | |
Class Schedule ... | |
belongs_to :doctor |
This file contains 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
# Add javascript-like functionality to Hash: | |
# write hash.prop instead of hash['prop'] | |
# | |
# NB: Your keys must NOT be named like standard methods of Hash | |
# In such case, use normal notation, e.g. hash['key'] | |
# | |
# So it is kinda dangerous hack! | |
class Hash | |
def method_missing(meth, *args) | |
method = meth.to_s # Symbol -> String |
This file contains 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
# Check if it is present... | |
if row[1].present? | |
# If it is present: | |
# Check if it is a subclass of numeric... | |
if row[1].is_a? Numeric | |
# If it is present AND it is a number: | |
oem = row[1].to_i.to_s # <- Convert it to string | |
else | |
# If it is present BUT is not a number: | |
oem = row[1] # ...then it is string, conversion not required |
This file contains 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
// Example 1: join two collections of filenames, find existing ones and load them | |
(configFiles ++ extraConfigFiles) map { new File(_) } filter { _.canRead } foreach load | |
// Example 2: invoke `prompt` function in an infinite loop, transform the result with trim method, filter out non-empty and process the others | |
Iterator continually(prompt) map { _.trim } filterNot { _.isEmpty } foreach { input => ... } |