Skip to content

Instantly share code, notes, and snippets.

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

fukaoi fukaoi

:octocat:
deep dive in codes
View GitHub Profile
@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

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 / 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
@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 / 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 / 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 / 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 / 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 / adaptor.cr
Last active June 11, 2018 13:52
Adapter pattern in crystal-lang
class Demo
@obj: Coin
def initialize(name : String)
if name == "LTC"
@obj = LTC.new
elsif name == "ETH"
@obj = ETH.new
else
raise "Not found name"
end
@fukaoi
fukaoi / aws_cloudwatch_put_log.sh
Created June 9, 2018 15:29
Put cutom log on aws cloudwatch
#!/bin/bash
DATE=`date "+%s"`
echo $DATE
DATE2=$(($DATE*2))
echo $DATE2
aws logs put-log-events --log-group-name scorpio --log-stream-name app --log-events timestamp=$DATE2,message="Test event 1" --sequence-token $1