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 / 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|
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
.video { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; }
.video img { position: absolute; display: block; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; cursor: pointer; }
.video:after { content: ""; position: absolute; display: block;
background: url(play-button.png) no-repeat 0 0;
top: 45%; left: 45%; width: 46px; height: 36px; z-index: 30; cursor: pointer; }
.video iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
/* image poster clicked, player class added using js */
.video.player img { display: none; }
.video.player:after { display: none; }