Skip to content

Instantly share code, notes, and snippets.

@jooeycheng
jooeycheng / ts-complex-enum.ts
Created February 3, 2023 02:15
TypeScript Notes
class Material {
public static readonly ACRYLIC = new Material(`ACRYLIC`, `AC`, `Acrylic`);
public static readonly ALUM = new Material(`ALUM`, `AL`, `Aluminum`);
public static readonly CORK = new Material(`CORK`, `CO`, `Cork`);
public static readonly FOAM = new Material(`FOAM`, `FO`, `Foam`);
// private to diallow creating other instances of this type.
private constructor(public readonly key: string, public readonly id: string, public readonly name: string) {}
public toString(): string {
@jooeycheng
jooeycheng / profile-pin.md
Last active June 24, 2020 04:12
Searchlight for Google Slides
@jooeycheng
jooeycheng / Awesome Free Apps.md
Last active June 24, 2020 03:43
Awesome Free Web Apps (No Logins)
@jooeycheng
jooeycheng / typescript-function-vs-class.md
Last active June 24, 2020 04:03
TypeScript Function vs Class approach

Class

export class OrderCreationValidator {
  validateParams (params: OrderCreationParams) {
    this.validateAccountId(params)
    this.validateSku(params)
  }

  private validateAccountId(params: OrderCreationParams) {
@jooeycheng
jooeycheng / nodejs-dynamodb-cheat-sheet.js
Last active June 24, 2020 03:58
NodeJS DynamoDB Cheat Sheet (straight to the point!)
// Simplified from https://github.com/dabit3/dynamodb-documentclient-cheat-sheet
/**
* DynamoDB.DocumentClient
*/
const dynamoDbClient = new AWS.DynamoDB.DocumentClient({
region: 'ap-southeast-1',
convertEmptyValues: true,
httpOptions: {
connectTimeout: 1000, // 1s
@jooeycheng
jooeycheng / my-javascript-notes.md
Last active February 11, 2021 06:01
My JavaScript notes, excerpts from https://javascript.info/
@jooeycheng
jooeycheng / ReactComponentSample.js
Last active June 24, 2020 03:55
Example React Component (cheatsheet)
/**
* Sample Component file for reference, because Joey forgets simple stuff.
*/
import React from 'react';
import './Sample.scss';
class Sample extends React.Component {
constructor(props) {
super(props);
@jooeycheng
jooeycheng / ruby-capybara-poltergeist-phantomjs-cheatsheet.rb
Last active June 24, 2020 03:57
Capybara Poltergeist (PhantomJS) Cheatsheet
# Setup
# ./spec/spec_helper.rb
Capybara.register_driver :poltergeist do |app|
options = {
debug: true, # debug mode, verbose logs
timeout: 30,
window_size: [360, 640],
phantomjs_options: [
'--proxy-type=none',

The RSpec

# spec/models/country_spec.rb

describe Country, type: :model do
  describe 'FactoryBot' do
    describe '.build' do
      it 'should .save! succesfully' do
        expect { build(:country).save! }.to change { Country.count }.by(1)
@jooeycheng
jooeycheng / setup-rails-app.md
Last active December 31, 2022 19:33
Ubuntu 16.04 - Rails + Capistrano + Passenger + Nginx