Skip to content

Instantly share code, notes, and snippets.

View fukaoi's full-sized avatar
:octocat:
deep dive in codes

AKIRA / fukaoi fukaoi

:octocat:
deep dive in codes
View GitHub Profile
@fukaoi
fukaoi / monomorphism_proxy.cr
Last active June 21, 2018 11:24
Crystal Monomorphism example code
abstract class Parent #同じシグネチャなので、abstractを通して、制約をつける
abstract def disp
end
class A < Parent
def disp : String
"call A"
end
end
@fukaoi
fukaoi / polymorphism_proxy.cr
Last active June 21, 2018 11:24
Crystal Polymorphism example code
class A
def disp : String
"call A"
end
end
class B
def disp : String
"call B"
end
@fukaoi
fukaoi / call_crytal_env.cr
Created June 21, 2018 09:03
crystal-envのrequire代替手段
### これだとMacro?生成ができないのか、 ``` undefined constant Crystal::Env```
### [NG]
require "env"
### 代替手段
### [OK]
require "env/core"
@fukaoi
fukaoi / macro.cr
Created July 11, 2018 14:14
Macro example
module Demo
STRUCT = [
Bool, Char, Symbol,
Int8, Int16, Int32, Int64, Int128,
Float32, Float64
]
macro define_struct
{% for s in STRUCT %}
struct {{ s.id }}
@fukaoi
fukaoi / create-wallet.elt
Last active July 26, 2018 01:00
Create new wallet by electrum-ltc
## default
>electrum-ltc create --testnet -w ~/Desktop/wallet
<<Password (hit return if you do not wish to encrypt your wallet):
>>test
<<Confirm:
>>test
## set env parameter
@fukaoi
fukaoi / docker-postgre.sh
Created September 19, 2018 13:42
postgreSQL on Dockder
docker run -d -p 5432:5432 -v /var/run/postgresql/:/var/run/postgresql/ --name mypost postgres

Keybase proof

I hereby claim:

  • I am fukaoi on github.
  • I am fukaoi (https://keybase.io/fukaoi) on keybase.
  • I have a public key ASCUo-T8fcPOYbwnpufKBq85MsJs_sMYCq8i3C1Hxx-h3Qo

To claim this, I am signing this object:

@fukaoi
fukaoi / crystal_pack.cr
Created October 17, 2018 01:58
crystal pack and unpack
class String
def unpack(format : String) : Array
io = IO::Memory.new(self)
slice = Bytes.new(self.size)
io.read(slice)
[slice.hexstring]
end
end
class Array
@fukaoi
fukaoi / send.js
Created April 23, 2019 12:50
node.js to crystal named pipe
const exec = require('child_process').exec;
var obj = {
"name":"太郎",
"age": 30,
"area":"Tokyo"
}
const json = JSON.stringify(JSON.stringify( obj ));
console.log(json)
@fukaoi
fukaoi / receive.cr
Created April 23, 2019 12:51
node.js to crystal named pipe
require "io"
require "json"
io = IO::Memory.new
Process.run("cat ~/Work/hogepipe", shell: true, output: io)
p data = io.to_s.chomp
p JSON.parse(data)["name"]