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 s(l, start, stop, accuracy = 1000000) | |
range = stop - start | |
dx = range / accuracy.to_f | |
sum = 0 | |
accuracy.times do | |
sum += 0.5 * (l.(start) + l.(start + dx)) * dx | |
start += dx | |
stop += dx | |
end | |
sum |
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 List(T) | |
class Node(T) | |
property :value | |
property :next | |
def initialize(@value : T, @next : List::Node(T) | List::EmptyNode) | |
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
defmodule HeaderReader do | |
def read(conn) do | |
{:ok,headers} = Agent.start_link(fn -> %{} end) | |
init_line = :gen_tcp.recv(conn, 0) | |
do_read(headers, conn, :gen_tcp.recv(conn, 0)) | |
end | |
defp do_read(headers, conn, {:ok, "\r\n"}) do | |
IO.inspect Agent.get headers, fn state -> state end | |
:gen_tcp.close conn |
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
defmodule Tr do | |
def tr(ast, fun) do | |
case fun.(ast) do | |
{x1, x2, [x3, x4]} -> {x1, x2, [tr(x3, fun), tr(x4, fun)]} | |
{x1, x2, x3} -> {x1, x2, tr(x3, fun)} | |
x -> x | |
end | |
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
class Promise | |
def initialize(&blk) | |
@functions = [blk] | |
end | |
def then(&blk) | |
@functions << blk | |
end | |
def run |
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
defmodule Promise do | |
defstruct functions: [] | |
def new(), do: %Promise{} | |
def new(func), do: %Promise{functions: [func]} | |
def then(%Promise{functions: functions} = promise, func) do | |
Map.put promise, :functions, [func | functions] | |
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
# Carrierwave works incorrectly with file formatting. If you do not override | |
# path and url methods it will return you incorrect path and url to webp file | |
# respectively. Also you should add removing callback because Carrierwave could | |
# not delete webp file by itself because of incorrect path. | |
# Remove this hacks if this issue will be fixed. | |
class ItemGalleryUploader < ApplicationUploader | |
WEBP_VERSION_NAME = :webpver | |
def filename | |
splitted = original_filename.split('.') |
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
# Carrierwave works incorrectly with file formatting. If you do not override | |
# path and url methods it will return you incorrect path and url to webp file | |
# respectively. Also you should add removing callback because Carrierwave could | |
# not delete webp file by itself because of incorrect path. | |
# Remove this hacks if this issue will be fixed. | |
class ItemGalleryUploader < ApplicationUploader | |
WEBP_VERSION_NAME = :webpver | |
WEBP_CONV_OPTIONS = {quality: 80, method: 5}.freeze | |
before :remove, :clear_webp_file |
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
import torch | |
from torch import nn | |
import numpy as np | |
net = nn.Sequential( | |
torch.nn.Linear(2, 1) | |
) | |
def fun(x1, x2): | |
return 2 * x1 + 3 * x2 + 5 |
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
pipeline = [] | |
define_method :use, -> middleware do | |
pipeline.unshift(middleware) | |
end | |
class One | |
def initialize(app) | |
@app = app | |
end |
OlderNewer