<commit_before>linkit
======

Share links and posts.

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-12-07.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-12-03-1.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-11-25-2.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-10-14.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-10-09.png)

### To-do List

- Production with http version.
- Capybara and integration test should on.
- prepare to deploy.
- Email links should direct to **production** url.

### AWS example

- [http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html)
- [http://www.rubydoc.info/github/aws/aws-sdk-ruby/AWS/S3/S3Object:url_for](http://www.rubydoc.info/github/aws/aws-sdk-ruby/AWS/S3/S3Object:url_for)
- object is a k-v pair, key represent the path to that object.
  - ex: sub folder of bucket root, `/images` will be set as `key: images/`.
  - `client.put_object(bucket_name: "#{bucket_name}", key: "images/#{name}", acl: "public-read", data: file)`, file is a File object which support `#read` method.

### AJAX call

- `ajaxSuccess` listen to the ajax call from document.
- `$.ajax().success()` fire a ajax request.

```ruby
# set form or any POST request to `remote: true`
form_for root_path, remote: true do |f|
  # do something
end

# set action respond to javascript.
def action
  respond_to do |f|
    # instance variables can be called in that template.
    f.js { render "js_file/erb" }
  end
end

# append proper node to current DOM.
```

#### Security

- each user access application, a new session will create on server side and send a cookie to client.
- Then application store user id to that session, from now on, every request, the application load user by user id in session.
- The session id in cookie identify the proper session in application.
- To secure cookie => force SSL connection.
- In Rails 2, store session to client side rather than server by CookieStore.
  * Rails will get session hash from client and does not require session id for every request anymore.
  * To prevent session hash tampering, a digest (with SHA1) is calculated from the session with a server-side secret and inserted into the end of the cookie.
- `config.secret_key_base` to customed a key for the SHA1 algorithm.
- In same domain, cookie sent from server and server get client cookie in later every request.
- Cookie store user data, Session store the identity for the user.

### Done Work & Notes

07/20/2015

- Fix facebook image redirection issue. Try ope that uri, if response coed is 302 then get the redirect location as image url instead.
- Create `Procfile`

  ```sh
  worker: bundle exec sidekiq
  ```

- Deploy to Heroku, set up Sidekiq and Redis by add worker process
- [Heroku support Ruby version](https://devcenter.heroku.com/articles/ruby-support#supported-runtimes)

12/18/2014

- Address image url redirection problem, should send upload to MiniMagick too.
- Now user image use data-uri instead.
- Try move image assets to Cloudinary CDN, should remove data-uri.

12/15/2014

- after render, the smae class element selector will not be bind again.
- Compress ja and css file, ready to deploy.
- Add `Rack::Deflator` before `ActionDispatch::Static` for encoding response as gzip compression.
- Replace `u100.png` and `u40.png` to data uri.
- Precompile assets and refine redundant js code, always put embedly preview in last line of the script.
- Customize Kaminari paginator to always display none.

12/14/2014

- Hash in Sidekiq, use string as key instead of symbols. Sidekiq only use simple JSON types.<commit_msg>fix Cloudinary URL in production<commit_after>linkit
======

Share links and posts.

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-12-07.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-12-03-1.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-11-25-2.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-10-14.png)

![](https://github.com/jamesyang124/linkit/blob/master/Screenshot2014-10-09.png)

### To-do List

- Production with http version.
- Capybara and integration test should on.
- prepare to deploy.
- Email links should direct to **production** url.

### AWS example

- [http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html)
- [http://www.rubydoc.info/github/aws/aws-sdk-ruby/AWS/S3/S3Object:url_for](http://www.rubydoc.info/github/aws/aws-sdk-ruby/AWS/S3/S3Object:url_for)
- object is a k-v pair, key represent the path to that object.
  - ex: sub folder of bucket root, `/images` will be set as `key: images/`.
  - `client.put_object(bucket_name: "#{bucket_name}", key: "images/#{name}", acl: "public-read", data: file)`, file is a File object which support `#read` method.

### AJAX call

- `ajaxSuccess` listen to the ajax call from document.
- `$.ajax().success()` fire a ajax request.

```ruby
# set form or any POST request to `remote: true`
form_for root_path, remote: true do |f|
  # do something
end

# set action respond to javascript.
def action
  respond_to do |f|
    # instance variables can be called in that template.
    f.js { render "js_file/erb" }
  end
end

# append proper node to current DOM.
```

#### Security

- each user access application, a new session will create on server side and send a cookie to client.
- Then application store user id to that session, from now on, every request, the application load user by user id in session.
- The session id in cookie identify the proper session in application.
- To secure cookie => force SSL connection.
- In Rails 2, store session to client side rather than server by CookieStore.
  * Rails will get session hash from client and does not require session id for every request anymore.
  * To prevent session hash tampering, a digest (with SHA1) is calculated from the session with a server-side secret and inserted into the end of the cookie.
- `config.secret_key_base` to customed a key for the SHA1 algorithm.
- In same domain, cookie sent from server and server get client cookie in later every request.
- Cookie store user data, Session store the identity for the user.

### Done Work & Notes

07/20/2015

- Change the type of User model's image column from string to text. So Base64 code can be stored.
- Fix facebook image redirection issue. Try ope that uri, if response coed is 302 then get the redirect location as image url instead.
- Create `Procfile`

  ```sh
  worker: bundle exec sidekiq
  ```

- Deploy to Heroku, set up Sidekiq and Redis by add worker process
- [Heroku support Ruby version](https://devcenter.heroku.com/articles/ruby-support#supported-runtimes)

12/18/2014

- Address image url redirection problem, should send upload to MiniMagick too.
- Now user image use data-uri instead.
- Try move image assets to Cloudinary CDN, should remove data-uri.

12/15/2014

- after render, the smae class element selector will not be bind again.
- Compress ja and css file, ready to deploy.
- Add `Rack::Deflator` before `ActionDispatch::Static` for encoding response as gzip compression.
- Replace `u100.png` and `u40.png` to data uri.
- Precompile assets and refine redundant js code, always put embedly preview in last line of the script.
- Customize Kaminari paginator to always display none.

12/14/2014

- Hash in Sidekiq, use string as key instead of symbols. Sidekiq only use simple JSON types.
{'fraction_non_alphanumeric': 0.1039571633799138, 'fraction_numerical': 0.027948282617213008, 'mean_word_length': 3.9630589760207386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 12, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6212834', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2290, 'n_words': 917}