Skip to content

Instantly share code, notes, and snippets.

View yihyang's full-sized avatar
😰
kinda busy

Yih Yang yihyang

😰
kinda busy
View GitHub Profile
@yihyang
yihyang / data_validator_spec.rb
Last active August 21, 2018 17:51
Rspec testing validator
require 'rails_helper'
class Validatable
include ActiveModel::Validations
attr_accessor :data
validates :data, lead_data: true
end
describe DataValidator do
subject { Validatable.new }
@yihyang
yihyang / change-random-wallpaper.sh
Created July 25, 2018 04:15
Make fun of your friend by changing their wallpaper fast using this program. Start by putting all the wallpapers inside "wallpapers" folder on Desktop.
cd ~/Desktop/wallpapers
# find the available files
photos=`find ${PWD} -type f -maxdepth 2 -name "*.jpg" -o -name "*.png"`
# Select Random photos
numlines="$(printf "%s\n" "${photos}" | wc -l)"
lineno="$((${RANDOM} % ${numlines} + 1))"
random_line="$(printf "%s\n" "${photos}" | sed -n "${lineno}{p;q;}")"
@yihyang
yihyang / docker-cloud9.sh
Last active July 6, 2018 04:26
Docker Cloud9 Setup Script, run it using
# run it using bash <(curl https://gist.githubusercontent.com/yihyang/0186b3b0817f8ea4f0014ea3380e661a/raw)
##########
# docker #
##########
# setup docker
docker run -it -d -p 80:80 kdelfour/cloud9-docker
########
# ruby #
@yihyang
yihyang / SQL-CheatSheet.sql
Last active June 30, 2018 16:20
SQL CheatSheet
# FOR LOOP - SQL
do $$
begin
for r in 1..100000 loop
insert into events(id,location_id, status) values(r,1,'ACTIVE');
end loop;
end;
$$;
# LOOP INSERT
@yihyang
yihyang / bookshelf.js
Created June 28, 2018 15:06
BookshelfJS Notes
var activeEvents = yield new Model.Event()
.query(function(qb) {
qb.where('status', 'ACTIVE').orderBy('id', 'DESC').limit(5)
})
.fetchAll({
withRelated: [
'host',
'location.facilities',
]
});
@yihyang
yihyang / app.js
Created June 9, 2018 04:21
Simple HTTP Server written in NodeJS with Response from JSON File
var http = require('http');
var fs = require('fs');
var port = "8080" ;
http.createServer(function(request, response) {
response.writeHead(200, {
'Content-Type': 'text/json',
'Access-Control-Allow-Origin': '*',
'X-Powered-By':'nodejs'
@yihyang
yihyang / rename_products_to_finished_goods.js
Created March 28, 2018 16:18
KnexJs Multiple Table In Single Migration
exports.up = function(knex, Promise) {
return renameProductsTable()
.then(updateRecordsReferences)
.then(updateSummariesReferences);
function renameProductsTable() {
return knex.schema.renameTable('products', 'finished_goods');
}
@yihyang
yihyang / metatags-matcher
Created February 11, 2018 03:14
Rspec Metatags Matcher
within('head', visible: false) do
expect(page.body).to have_selector('title', text: title, visible: false)
expect(page).to have_css(%!meta[name="description"][content="#{description}"]!, visible: false)
expect(page).to have_css(%!link[hreflang="en"][rel="alternate"]!, visible: false)
expect(page).to have_css(%!link[hreflang="id"][rel="alternate"]!, visible: false)
expect(page).to have_css(%!meta[property="og:locale"][content="zh_HK"]!, visible: false)
expect(page).to have_css(%!meta[property="og:locale:alternate"][content="id_ID"]!, visible: false)
expect(page).to have_css(%!meta[property="og:locale:alternate"][content="en_US"]!, visible: false)
expect(page).to have_css(%!meta[property="og:title"][content="#{title}"]!, visible: false)
expect(page).to have_css(%!meta[property="og:description"][content="#{description}"]!, visible: false)
{
"ensure_newline_at_eof_on_save": false,
"font_size": 11,
"ignored_packages":
[
"Vintage"
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,