Skip to content

Instantly share code, notes, and snippets.

View yanzay's full-sized avatar

Alexey Grachov yanzay

View GitHub Profile
def quartile(array)
return array.first if array.length <= 1
sorted = array.sort
quartile_position = 0.25 * (3 * sorted.length + 1)
quartile_int = quartile_position.to_i
lower = sorted[quartile_int - 1]
upper = sorted[quartile_int]
lower + (upper - lower) * (quartile_position - quartile_int)
end
def quartile(array, q=3)
return array.first if array.length <= 1
sorted = array.sort
return sorted.last if q == 4
quartile_position = 0.25 * (q*sorted.length + 4 - q)
quartile_int = quartile_position.to_i
lower = sorted[quartile_int - 1]
upper = sorted[quartile_int]
lower + (upper - lower) * (quartile_position - quartile_int)
end
class InversionsCalculator
def inversions_count(arr)
sort_and_count(arr)[0]
end
private
def sort_and_count(arr)
return [0, arr] if arr.length == 1
a, b = split_array(arr)
@yanzay
yanzay / sublime
Last active February 1, 2017 16:25
// ~/Library/Application Support/Sublime Text 3/Packages/User/Preferences.sublime-settings
{
"auto_complete_delay": 10,
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"font_options":
[
"subpixel_antialias"
],
"font_size": 17,
"highlight_line": true,
@yanzay
yanzay / designer.html
Last active August 29, 2015 14:18
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../topeka-elements/avatars.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../paper-button/paper-button.html">
zookeeper:
image: garland/zookeeper
ports:
- "2181:2181"
mesos-master:
image: mesosphere/mesos-master:0.28.0-2.0.16.ubuntu1404
hostname: mesos-master
ports:
- "5050:5050"

Keybase proof

I hereby claim:

  • I am yanzay on github.
  • I am yanzay (https://keybase.io/yanzay) on keybase.
  • I have a public key whose fingerprint is 984A E7C1 47E3 9A2A 08E6 2B2B C821 E9DD 0B55 9E16

To claim this, I am signing this object:

var (
listen = flag.Bool("l", false, "Listen")
host = flag.String("h", "localhost", "Host")
// Default 0 port means to choose random one
port = flag.Int("p", 0, "Port")
)
func main() {
flag.Parse()
if *listen {
startServer()
return
}
}
func startServer() {
// compose server address from host and port
addr := fmt.Sprintf("%s:%d", *host, *port)
// launch TCP server
listener, err := net.Listen("tcp", addr)
if err != nil {
// if we can't launch server for some reason,
// we can't do anything about it, just panic!
panic(err)