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
@yowchun93
yowchun93 / let_implementation.rb
Last active March 22, 2020 06:28
Let implementation
def describe(description, &block)
Describe.new(description, block).run
end
class Describe
def initialize(description, block)
@description = description
@block = block
end
@yowchun93
yowchun93 / runner.rb
Last active March 17, 2020 14:19
Rspec from scatch: Assertion
expect(1 + 1)
=> #<Actual:0x00007fa4491e4fc0 @actual=2>
expect(1 + 1).to(eq(2))
eq(2)
=>
expect do
raise ArgumentError.new
@yowchun93
yowchun93 / chain.rb
Created March 11, 2020 03:20
Malaysian Chains
chains = Chain.all.select { |chain| chain.agents_all_commission >= 30 }.select { |chain| chain.agents.map(&:country).include?("MY") }
chains.map { |chain| chains.agents.map(&:country) }
## 109 are malaysian agents.
@yowchun93
yowchun93 / react_router.js
Last active March 11, 2020 00:13
RoutesJS
import React, { Component } from 'react'
## Routers are components as well
const Home = () => {
<div>
Home
</div>
}
import { battle } from '../utils/api'
constructor(props) {
super(props)
this.state = {
winner: null,
loser: null,
error: null,
loading: true
@yowchun93
yowchun93 / popularJsRefactor.js
Created March 7, 2020 13:53
Refactor Popular.js component to use hooks
// look at the states used in Popular.js
// States.
constructor(props) {
super(props)
this.state = {
selectedLanguage: 'All',
repos: {},
error: null
@yowchun93
yowchun93 / useContext.js
Created March 7, 2020 13:01
useContext
// This is very interesting because, just 1 little change to useContext brings so much benefits to the codebase
export default function Nav() {
const { locale, toggleLocale} = React.useContext(
)
}
// update code from using LocaleContext.Consumer to useContext
@yowchun93
yowchun93 / useReducer.js
Created March 7, 2020 05:42
useReducer
function reducer(state, action) {
switch (action.type) {
case "fetch":
return {
...state,
loading: true
};
case "success":
return {
data: action.data,
@yowchun93
yowchun93 / shopify_template.rb
Last active March 6, 2020 13:18
Using shopify's liquid for templating
We recently have this feature, where we provide customer's ability to edit / modify content shown in an email.
1. We need a templating language, something which is not too confusing for customers.
2. Data from customers need to be sanitized before it is run in the application. In the case of customer putting something like
<%= User.delete_all %>
3.
def template_renderer(shop)
template = ActionController::Base.renderer.new.render(tempalte: template_file)
Liquid::Template.parse(template)
## returns a Liquid::Template object
@yowchun93
yowchun93 / generics.cs
Created March 6, 2020 01:33
c# generics
// something