Skip to content

Instantly share code, notes, and snippets.

View leechunhoe's full-sized avatar

Lee Chun Hoe leechunhoe

View GitHub Profile
# Get my own git branches
keyword="$(git config user.name) refs\/heads\/"
git for-each-ref --format=' %(authorname) %(refname)' --sort=authorname | grep $keyword | sed "s/$(echo $keyword)//g"
@leechunhoe
leechunhoe / clean_git_branches.sh
Last active April 6, 2020 01:42
Delete merged/gone local git branches (bash/zsh)
# Delete git branches with status [gone] (bash/zsh)
git branch -v | grep "\[gone\]" | awk 'END {FS="\t"}; {print $1}' | xargs git branch -D
@leechunhoe
leechunhoe / MyViewModelTest.kt
Last active April 25, 2019 07:14
Template of view model unit test with Kotlin (androidTest)
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import com.myapp.MyActivity
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MyViewModelTest {
@leechunhoe
leechunhoe / pageable_type.rb
Last active November 29, 2018 08:08
GraphQL type to be extended for offset pagination
class Types::PageableType < GraphQL::ObjectType
# Generalised pagination
def define_connection(**kwargs, &block)
this_type = self
super do
field :edges do
type !types[this_type]
resolve ->(obj, args, _ctx) {
page = obj.arguments[:page] || 1
<CORSRule>
<AllowedOrigin>http://localhost:5000</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
@leechunhoe
leechunhoe / FileUpload.js
Last active November 9, 2022 15:36
Minimal file upload React.js component
import React, { Component } from 'react';
const S3 = require('aws-sdk/clients/s3');
const AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: [Your AWS access key ID (from ~/.bashrc)],
secretAccessKey: [Your AWS secret access key (from ~/.bashrc)]
});
class FileUpload extends Component {