Skip to content

Instantly share code, notes, and snippets.

View yoonwaiyan's full-sized avatar
🏠
Working from home

Wai Yan Yoon yoonwaiyan

🏠
Working from home
View GitHub Profile
@yoonwaiyan
yoonwaiyan / routes_csv.rake
Created April 1, 2024 02:34 — forked from lissdy/routes_csv.rake
Export rails routes to csv
namespace :routes do
desc 'Print out all defined routes in CSV format.'
task :csv => :environment do
class CSVFormatter
def initialize
@buffer = []
end
def result
@yoonwaiyan
yoonwaiyan / caesar_cipher.rb
Last active March 2, 2018 12:05
Caesar Cipher
class CaesarCipher
def initialize(shift)
@shift = shift
end
def call(input)
[capital_characters, small_characters].each do |chars|
input = input.tr(chars.join, encrypt(chars).join)
end
@yoonwaiyan
yoonwaiyan / snapshot_restorer.rb
Created June 15, 2017 09:20
Restore an instance volume with existing snapshot.
# modified/rewrite from http://gist.github.com/cNeha/4eddaa1aabe112b72976e06cb2dbfa54
require 'aws-sdk'
class SnapshotRestorer
PROVIDER_REGION = "<region>"
SNAPSHOT_ID = '<snapshot_id>'
attr_reader :ec2, :target_instance_id, :dry_run_mode
def initialize(args = {})
@ec2 = get_ec2
"{"International Date Line West":"Pacific/Midway","Midway Island":"Pacific/Midway","American Samoa":"Pacific/Pago_Pago","Hawaii":"Pacific/Honolulu","Alaska":"America/Juneau","Pacific Time (US \u0026 Canada)":"America/Los_Angeles","Tijuana":"America/Tijuana","Mountain Time (US \u0026 Canada)":"America/Denver","Arizona":"America/Phoenix","Chihuahua":"America/Chihuahua","Mazatlan":"America/Mazatlan","Central Time (US \u0026 Canada)":"America/Chicago","Saskatchewan":"America/Regina","Guadalajara":"America/Mexico_City","Mexico City":"America/Mexico_City","Monterrey":"America/Monterrey","Central America":"America/Guatemala","Eastern Time (US \u0026 Canada)":"America/New_York","Indiana (East)":"America/Indiana/Indianapolis","Bogota":"America/Bogota","Lima":"America/Lima","Quito":"America/Lima","Atlantic Time (Canada)":"America/Halifax","Caracas":"America/Caracas","La Paz":"America/La_Paz","Santiago":"America/Santiago","Newfoundland":"America/St_Johns","Brasilia":"America/Sao_Paulo","Buenos Aires":"America/Argentina/
@yoonwaiyan
yoonwaiyan / Bootstrap Navbar with Devise integration - Basic.erb
Created February 13, 2017 06:33 — forked from PlanetRoast/Bootstrap Navbar with Devise integration - Basic.erb
Bootstrap powered responsive navbar for your Rails project with some Devise related links baked in.
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<%= link_to 'Project', root_path, :class => 'navbar-brand' %>
@yoonwaiyan
yoonwaiyan / meteor-async.md
Created November 30, 2016 10:08 — forked from joscha/meteor-async.md
Meteor Async Guide

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished.

@yoonwaiyan
yoonwaiyan / MyReactComponent.js
Created April 2, 2016 05:17 — forked from thmain/MyReactComponent.js
Skeleton React Component with descriptions for all of its lifecycle methods
/**
* @jsx React.DOM
*/
var React = require('react'),
MyReactComponent = React.createClass({
// The object returned by this method sets the initial value of this.state
getInitialState: function(){
return {};
@yoonwaiyan
yoonwaiyan / gist:679b45b92085d23b8506
Created March 7, 2016 06:09 — forked from windix/gist:2970224
Download codetv videos from codeschool.com (account required)
require 'bundler/setup'
require 'mechanize'
require 'open-uri'
agent = Mechanize.new
# agent.set_proxy 'localhost', 3128
# login
agent.get('https://www.codeschool.com/users/sign_in') do |page|
result = page.form_with(:action => '/users/sign_in') do |form|
@yoonwaiyan
yoonwaiyan / _flash_message.html.erb
Created August 28, 2015 15:33
Rails Flash Message Partial for Bootstrap
<% flash.each do |key, value| %>
<% key = "success" if key == "notice" %>
<% key = "danger" if key == "error" %>
<div class="alert alert-<%= key %>">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong><%= value %></strong>
</div>
<% end %>
@yoonwaiyan
yoonwaiyan / .gitignore_global
Created August 14, 2015 08:00
gitignore global
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #