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
vers = [%{name: "js", ver: 1}, %{name: "c", ver: 3}, %{name: "elixir", ver: 1.74}] | |
langs = [%{ id: 1, name: "elixir"}, %{ id: 2, name: "js"}] | |
langs |> Enum.map( fn rec -> %{ id: rec.id, rec: rec.name, ver: Enum.find(vers, fn v -> v.name == rec.name end)[:ver]} end) |
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
defmodule Imagenet do | |
@urls_filename "urls/fall11_urls.txt" | |
@words_filename "urls/words.txt" | |
@moduledoc """ | |
# Image-netのスクレイピング用スクリプト | |
``` | |
defp deps do | |
[ |
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
defmodule NIFThread.Receiver do | |
use GenServer | |
def start_link(init_list\\[]) do | |
GenServer.start_link(__MODULE__, init_list) | |
end | |
def init(list) do | |
{:ok, list} | |
end |
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
extern crate scoped_pool; | |
use rustler::types::pid::Pid; | |
lazy_static! { | |
static ref POOL: scoped_pool::Pool = scoped_pool::Pool::new(8); | |
} | |
fn map_calc_send<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> { | |
let mut my_env = OwnedEnv::new(); |
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
defmodule Flowtest do | |
@chunk 10 | |
def run( counts \\ 100, stages \\ 4 ) do | |
window = Flow.Window.global | |
|> Flow.Window.trigger_every(@chunk, :reset) #トリガーの定義 | |
0..counts | |
|> Flow.from_enumerable | |
|> Flow.partition(window: window, stages: stages, hash: fn event -> {event, rem(div(event, @chunk), stages) } end ) | |
|> Flow.reduce(fn -> [] end, fn e, acc -> [e | acc] end) | |
|> Flow.map_state(fn e -> Enum.reverse(e) end) |
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
#[macro_use] extern crate rustler; | |
#[macro_use] extern crate rustler_codegen; | |
#[macro_use] extern crate lazy_static; | |
extern crate kana; | |
use rustler::{NifEnv, NifTerm, NifResult, NifEncoder}; | |
use rustler::types::atom::NifAtom; | |
use rustler::types::map::NifMapIterator; | |
use kana::*; |
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
defmodule IsingEts do | |
@moduledoc """ | |
Documentation for Ising. | |
map reduce version | |
Iex > Ising.main() | |
""" | |
defp get_state(ary2d, idx) do | |
:ets.lookup_element(ary2d, elem(idx,0)*1000+elem(idx,1) , 2) | |
end |
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
# | |
# GenStage PartitionDispatcher Example | |
# | |
# reference: http://www.elixirfbp.org/2016/08/genstage-example-no-3-dispatching.html | |
defmodule Comsumer do | |
use GenStage | |
def start_link(state) do | |
GenStage.start_link(__MODULE__, state) |
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
# ussage: | |
# GenStageTest.run() | |
# | |
defmodule A do | |
use GenStage | |
def start_link(number) do | |
GenStage.start_link(A, number) | |
end |
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
defmodule HotPepperApi do | |
@hit_per_page 50 | |
def get_shops({addr, freeword}) do | |
iget_shops({addr, freeword}, 1, []) | |
end | |
# ページング:最終ページ | |
def iget_shops({_addr, _freeword}, _offset, [%{:islast => true}|result] ) do | |
result | |
end |
NewerOlder