Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

chrisyeung1121

🏠
Working from home
View GitHub Profile
View ig-request.js
// node ig-request.js username
// 1. visit www.instagram.com/username?__a=1
// 2. save it as ${%Y%m%d}-${username}.json and upload it to a Google Cloud Storage Bucket
// 3. Automatically renew cookies so we can continue ot obtain JSONs
// 4. deploy it as a Cloud Function (bonus)
// 5. Health Monitor and logging. (bonus)
const request = require('request');
const fs = require('fs');
View output.yaml
- models:
- name: 1 Series
years:
- year: 2008
styles:
- submodel: 1 Series Convertible # Becomes "submodel > modelName"
trim: 128i
- submodel: 1 Series Coupe # Becomes "submodel > modelName"
trim: 128i
- submodel: 1 Series Coupe
View sample.json
{
"models": [
{
"id": "BMW_1_Series",
"name": "1 Series",
"niceName": "1-series",
"make": {
"id": 200000081,
"name": "BMW",
"niceName": "bmw"
View 11_algolia_nested_attribute.rb
class Car < ActiveRecord::Base
belongs_to :owner, class_name: 'FormUser', foreign_key: 'user_id'
include AlgoliaSearch
algoliasearch id: :permalink do
attribute :owner do
{ uid: owner.uid }
end
end
@chrisyeung1121
chrisyeung1121 / 10_AJAX_rebind_event.js
Created Jun 16, 2015
binding will work with AJAX created DOM
View 10_AJAX_rebind_event.js
// Will not work after new DOM created on AJAX
$('.photo-options-hero').on('click', function() {
$(this).closest('.gallery-item').addClass('hero').siblings().removeClass('hero');
});
// Will work after AJAX DOM Creation
$('body').on('click', '.photo-options-hero', function() {
$(this).closest('.gallery-item').addClass('hero').siblings().removeClass('hero');
});
@chrisyeung1121
chrisyeung1121 / video_to_gif.md
Created Apr 28, 2015
10_turn_video_to_gif_npm
View video_to_gif.md

Making videos into GIFs on the command-line with gifify I like making gifs.

You also probably like making gifs.

It's a thing we do.

On a regular basis I'll have video from television shows or movies or other video I've taken myself like screencasts that I want to turn into a gif.

Turning video into a gif can be done using online services, but I need a quick way to do it on the command line.

View 9_devise_learning.rb
## << Devise::RegistrationController
### Build an user (resource) object from temporary
build_resource(sign_up_params.select{|k,v| v.present?})
# > #<User id: nil, created_at: nil, updated_at: nil, email: "a@b.c", encrypted_password: "$2a$10$HufMLSGEoWzbwhVO.IRztuvE8NKTrQgaXNZthem3wid...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil>
### :validatable module in devise. (took me three hours)
# http://stackoverflow.com/questions/21103138/handle-activerecordrecordnotunique-in-devise-registrations-controller/29792359#29792359
# ActiveRecord::RecordNotUnique in Users::RegistrationsController#create
# PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email" DETAIL: Key (email)=() already exists. : INSERT INTO "users" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"
View 8_ruby_select.rb
def sign_up_params
params.require(:user).permit(:email,:password)
end
# If user input :email => 'chris@mac.com', :password=> nil
puts sign_up_params
# $> {"email"=>"123@asdf.com", "password"=>""}
puts sign_up_params.select{|k,v| v.present?}
@chrisyeung1121
chrisyeung1121 / Tips.md
Last active Aug 29, 2015
Rails Deploying to Heroku Tips
View Tips.md

Adding PG to heroku (Database)

don't need to set database.yml, it is set automatically.

heroku addons:add heroku-postgresql:hobby-dev -a carshare-all

==============

@chrisyeung1121
chrisyeung1121 / 7_heroku_push.sh
Created Apr 21, 2015
Sprockets::FileNotFound: couldn't find file 'swiper/dist/js/swiper.jquery.js' with type 'application/javascript'
View 7_heroku_push.sh
Sprockets::FileNotFound: couldn't find file 'swiper/dist/js/swiper.jquery.js' with type 'application/javascript'
How to solve?