Skip to content

Instantly share code, notes, and snippets.

View leomao10's full-sized avatar

leo liang leomao10

  • Atlassian
  • Sydney
View GitHub Profile
@leomao10
leomao10 / ReportService.js
Last active July 18, 2019 02:59
Proposed error handling
const { ApiUnauthorized, ApiForbidden, ApiBaseError } = require('./lib/errors');
class ReportsService {
static async getOrganizationDetails({ orgId, container }) {
const response = await fetch();
switch (response.status) {
case 401: throw new ApiUnauthorized(response);
case 403: throw new ApiForbidden(response);
default: throw new ApiBaseError(response);
@leomao10
leomao10 / example.rb
Last active July 10, 2019 08:38
ActiveSupport::CurentAttributes surprise
class JwtCurrent < ActiveSupport::CurrentAttributes
attribute :jwt
end
# in api_controller.rb
def some_action
JwtCurrent.jwt = "something"
future = Concurrent::Future.execute do
puts "*" * 50
@leomao10
leomao10 / iterm2-solarized.md
Created August 31, 2018 11:43 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

# Reference http://stackoverflow.com/a/18490935/2037928
# Login as root
# Install needed packages
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
# Download appropriate ruby version https://www.ruby-lang.org/en/downloads/
@leomao10
leomao10 / error message in Chrome console
Last active December 30, 2015 10:59
Failing Prezi API
- VM10034:1 0ef9755629d2.js:2
Uncaught Error: Internal error on method getCurrentObject
(anonymous function)
d
- VM10040:1 0ef9755629d2.js:2
Uncaught Error: Internal error on method getCurrentObject
(anonymous function)
d
#!/bin/bash
# Takes one parameter: a remote git repository URL.
#
# This is the stuff this script does:
#
# 1. Clones the repository
# 2. Fetches all remote branches
# 3. Compresses the folder
# 4. Deletes the cloned folder.
require 'capistrano_colors'
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
require "rvm/capistrano"
require 'sidekiq/capistrano'
set :rvm_type, :system
set :rvm_ruby_string, :release_path
before 'deploy:setup', 'rvm:install_ruby'
@leomao10
leomao10 / application.js
Last active May 7, 2017 16:34
Turn SimpleForm DateTimeInput to JQuery Datetime Picker
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
@leomao10
leomao10 / gist:3003714
Created June 27, 2012 12:20
Class Methods vs Scope
class User < ActiveRecord::Base
scope :with_first_name, lambda { |first_name| where(:first_name => first_name) }
def self.with_last_name(last_name)
where(:last_name => last_name)
end
end
@leomao10
leomao10 / gist:2843511
Created May 31, 2012 13:45
Ruby 1.8.7 in Mountain Lion