Skip to content

Instantly share code, notes, and snippets.

@jooeycheng
jooeycheng / ruby_generate_pubkey.rb
Last active May 5, 2023 01:03
Ruby OpenSSL::PKey::RSA generate RSA Public Key from Modulus and Exponent
# [A] OpenSSL::PKey::RSA has undocumented `e=' and `n=' methods
exponent = "10001"
modulus = "9201EBD5DC974FDE613A85AFF2728627FD2C227F18CF1C864FBBA3781908BB7BD72C818FC37D0B70EF8708705C623DF4A9427A051B3C8205631716AAAC3FCB76114D91036E0CAEFA454254D135A1A197C1706A55171D26A2CC3E9371B86A725458E82AB82C848AB03F4F0AF3127E7B2857C3B131D52B02F9A408F4635DA7121B5B4A53CEDE687D213F696D3116EB682A4CEFE6EDFC54D25B7C57D345F990BB5D8D0C92033639FAC27AD232D9D474896668572F494065BC7747FF4B809FE3084A5E947F72E59309EDEAA5F2D81027429BF4827FB62006F763AFB2153C4A959E579390679FFD7ADE1DFE627955628DC6F2669A321626D699A094FFF98243A7C105"
rsa = OpenSSL::PKey::RSA.new
e = exponent.to_i(16)
n = modulus.to_i(16)
rsa.e = OpenSSL::BN.new(e)
rsa.n = OpenSSL::BN.new(n)
@jooeycheng
jooeycheng / ruby_dollar_signs.txt
Last active March 17, 2023 19:05 — forked from dvliman/gist:10402435
ruby dollar sign $ global variable
$: (Dollar Colon) is basically a shorthand version of $LOAD_PATH.
contains an array of paths that your script will search through when using require.
$0 (Dollar Zero) contains the name of the ruby program being run. This is typically the script name.
$* (Dollar Splat) is basically shorthand for ARGV. $* contains the command line arguments that were passed to the script.
$? (Dollar Question Mark) returns the exit status of the last child process to finish.
$$ (Dollar Dollar) returns the process number of the program currently being ran.
$~ (Dollar Tilde) contains the MatchData from the previous successful pattern match.
$1, $2, $3, $4 etc represent the content of the previous successful pattern match.
$& (Dollar Ampersand) contains the matched string from the previous successful pattern match.
$+ (Dollar Plus) contains the last match from the previous successful pattern match.
@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 / setup-rails-app.md
Last active December 31, 2022 19:33
Ubuntu 16.04 - Rails + Capistrano + Passenger + Nginx

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 / my-javascript-notes.md
Last active February 11, 2021 06:01
My JavaScript notes, excerpts from https://javascript.info/
@jooeycheng
jooeycheng / profile-pin.md
Last active June 24, 2020 04:12
Searchlight for Google Slides
@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 / 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',