Skip to content

Instantly share code, notes, and snippets.

View yowchun93's full-sized avatar
🇲🇾
Hello from Malaysia!

YC Yap yowchun93

🇲🇾
Hello from Malaysia!
View GitHub Profile
# Rails customer validation
#http://blog.arkency.com/2014/04/mastering-rails-validations-contexts/
# giving context to the validation
validates_length_of :slug, minimum: 3, on: :user
## editing , giving context when saving the record
def edit
@user = User.find(params[:id])
@yowchun93
yowchun93 / process.exs
Created January 16, 2019 01:31
Elixir Processes
run_query = fn(query_def) ->
:timer.sleep(2000)
"#{query_def} result"
end
#after 2 seconds -> "query 1 result"
run_query.("query 1")
# after 10 seconds result returns
1..5 |> Enum.map(&run_query.("query #{&1}"))
@yowchun93
yowchun93 / message_passing.ex
Last active January 16, 2019 13:20
Elixir Message Passing
## Kernel.send/2 function
send(pid, { :an, :arbitary, :term } )
receive do
pattern_1 -> do_something
pattern_2 -> do_something_else
## Example to be executed in IEX
send(self, "a message")
@yowchun93
yowchun93 / database_server.ex
Last active January 17, 2019 13:42
Elixir server
defmodule DatabaseServer do
def start do
spawn(&loop/0)
end
# public API
def run_async(server_pid, query_def) do
send(server_pid, {:run_query, self, query_def})
end
@yowchun93
yowchun93 / simple_calculator_server.ex
Last active January 20, 2019 09:27
Simple Elixir Calculator Server
defmodule Calculator do
def start do
spawn( fn -> loop(0) end)
end
defp loop(current_value) do
new_value = receive do
{sender_pid, :value} ->
IO.puts("current value is #{current_value}")
defmodule CamelCase do
def to_camel_case(word) do
words = String.codepoints(word)
convert("-", words) |> Enum.join("")
end
def convert(a, []) do
[]
end
@yowchun93
yowchun93 / github_battle_v2_setup.js
Created June 17, 2019 01:22
Rebuilding Github Battle
Github Battle v2
Step 1
// Setting up package.json, this is done through npm install
Step 2
// I guess the next step, is to get something to run?!! app.js? index.js?
// npm install --save-dev @babel/core @babel/preset-env @babel/preset-react webpack webpack-cli webpack-dev-server babel-loader css-loader style-loader html-webpack-plugin
Step 3
@yowchun93
yowchun93 / Popular.js
Last active June 18, 2019 13:09
Github Battle Navbar
@yowchun93
yowchun93 / repo_grid.js
Last active June 24, 2019 07:00
Github Repos Grid
19 June 2019
1. Create ReposGrid Component
2. For every object found in repos , create a list which displays the content
3. Also use font-awesome, to create the labels
A few questions:
1. Does the ul, and React Fragment still stay inside Popular component? or should be moved to RepoGrid?
Basically using composition / or whatever that means.
@yowchun93
yowchun93 / tasks.js
Created June 19, 2019 13:14
Finished Task
// 18 June 2019
1. Create Vietnam Retailer in Postco.xyz
2. Test Vietnam Return Flow, make sure label is there.
3.
Testing result
1. ParcelReturn.last.country = ‘VIETNAM’, why?? .
I think it’s because Agent’s country is ‘VIETNAM’
pdf.js