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
SET g TO 0.05 * 9.81. // minmus | |
// SET g TO 0.166 * 9.81. // mun | |
SET f TO 50. | |
LOCK m TO SHIP:MASS. | |
LOCK aTot TO g - F/m. | |
LOCK tThrottle TO v0 / aTot. | |
SET LANDED_ALTITUDE TO 10.0. |
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
# tallensin tämän, koska harva vitsi kuvaa yhtä hyvin sitä täsmällisyyttä, | |
# mitä matematiikassa vaaditaan :) | |
Insinööri, fyysikko ja matemaatikko olivat matkalla Skotlannissa. | |
Junasta he näkivät mustia lampaita laitumella. | |
"Hei, Skotlannissa lampaat ovat mustia!", huudahti insinööri. | |
- Ei, tiedämme vain, että ainakin jotkin lampaat Skotlannissa ovat mustia, totesi | |
fyysikko. | |
Viimeisenä matemaatikko ojensi molempia: "Väärin. Varmuudella voimme sanoa vain, |
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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import qualified Data.Text as Text | |
import Database.PostgreSQL.Simple | |
import Control.Monad | |
import Control.Applicative | |
import Data.Maybe | |
queryStuff :: IO () |
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
rot13 = map (rot13' pairs) where | |
pairs = (zip s1 s2) ++ (zip s2 s1) | |
s1 = ['a'..'m'] ++ ['A'..'M'] ++ ['0'..'4'] | |
s2 = ['n'..'z'] ++ ['N'..'Z'] ++ ['5'..'9'] | |
rot13' [] ch = c | |
rot13' ((p,q):cs) c = if c == p then q else (rot13' cs c) | |
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
def break_after_middle(s) | |
midpoint = s.length/2-1 | |
idx_after_middle = s[midpoint..-1].index(' ') | |
if idx_after_middle | |
idx = idx_after_middle + midpoint | |
s.dup.tap { |p| p[idx..idx] = '<br/>' } | |
else | |
s | |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>esclient-sample</groupId> | |
<artifactId>esclient-sample</artifactId> | |
<version>1.0-SNAPSHOT</version> |
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 SymbolizeHelper | |
extend self | |
def symbolize_recursive(hash) | |
{}.tap do |h| | |
hash.each { |key, value| h[key.to_sym] = transform(value) } | |
end | |
end | |
private |
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 BatchWorker | |
attr_reader :size | |
def initialize(size, &block) | |
@size = size | |
@buf = [] | |
@block = block | |
end | |
def write(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
# merge_by_common_key(:k, [ { k: 1, a: 2 }, { k: 1, b: 3 }, { k: 2, c: 4} ]) | |
# => [ { k: 1, a: 2, b: 3}, { k: 2, c: 4 } ] | |
def merge_by_common_key(key, list_of_hashes) | |
list_of_hashes.group_by { |h| h[key] }.map { |_, hs| fold_merge(hs) } | |
end | |
def fold_merge(hs) | |
hs.each_with_object({}) { |h, acc| acc.merge!(h) } | |
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
module FinderExtensions | |
def find_uniq!(cond) | |
res = where(cond) | |
res.first.tap do |r| | |
raise ActiveRecord::RecordNotFound unless r | |
raise ActiveRecord::ActiveRecordError, "multiple records found" if res[1] | |
end | |
end | |
end |