Skip to content

Instantly share code, notes, and snippets.

View chrisyeung1121's full-sized avatar
🌝
Working from Moon

Christopher Yeung chrisyeung1121

🌝
Working from Moon
View GitHub Profile
// 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');
- 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
{
"models": [
{
"id": "BMW_1_Series",
"name": "1 Series",
"niceName": "1-series",
"make": {
"id": 200000081,
"name": "BMW",
"niceName": "bmw"
@chrisyeung1121
chrisyeung1121 / 11_algolia_nested_attribute.rb
Created August 11, 2015 08:49
Algolia nested attributes error
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 June 16, 2015 12:44
binding will work with AJAX created DOM
// 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 April 28, 2015 06:37
10_turn_video_to_gif_npm

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.

## << 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: "[email protected]", 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"
@chrisyeung1121
chrisyeung1121 / 8_ruby_select.rb
Last active August 29, 2015 14:19
8_ruby_select
def sign_up_params
params.require(:user).permit(:email,:password)
end
# If user input :email => '[email protected]', :password=> nil
puts sign_up_params
# $> {"email"=>"[email protected]", "password"=>""}
puts sign_up_params.select{|k,v| v.present?}
@chrisyeung1121
chrisyeung1121 / Tips.md
Last active August 29, 2015 14:19
Rails Deploying to Heroku Tips

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 April 21, 2015 19:30
Sprockets::FileNotFound: couldn't find file 'swiper/dist/js/swiper.jquery.js' with type 'application/javascript'
Sprockets::FileNotFound: couldn't find file 'swiper/dist/js/swiper.jquery.js' with type 'application/javascript'
How to solve?