2017年5月8日 星期一

顯示部分字的方法 rails

<%= post.content[0,20] %>
最簡單,但html tag也會跑出來

Rails3之後已經預設不讓html tag逸出

解釋一下下面這個
raw是讓content逸出,但會對網站造成風險
strip_tags  移除html標籤
truncate 擷取前幾個字元
<%= truncate(strip_tags(raw(post.content)),:length=>200) %>


或是直接使用白名單sanitize
<%= sanitize( @event.description ) %>
參考資料
https://ihower.tw/rails/actionview-helpers.html#sec4

https://apidock.com/ruby/Curses/raw/class

http://stackoverflow.com/questions/10129408/show-only-some-words-from-post-as-preview

https://ruby-china.org/topics/6539

https://ruby-china.org/topics/599

bootstrap v3 v4 改版差異

改版差異,沒事改這個幹麼....

grid sytem

v3

.col-md-6 .col-md-offset-3


v4

.col-md-6 .offset-md-3



Shit!!It cost my 30 mins to debug this small change.

2017年5月4日 星期四

Rancher requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v1 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))

教學文章
https://blog.hellosanta.com.tw/%E7%B6%B2%E7%AB%99%E8%A8%AD%E8%A8%88/%E4%BC%BA%E6%9C%8D%E5%99%A8/%E8%A6%96%E8%A6%BA%E5%8C%96%E7%AE%A1%E7%90%86%E7%9C%BE%E5%A4%9A-docker-%E5%AE%B9%E5%99%A8%E8%88%87%E9%83%A8%E7%BD%B2%E7%9A%84%E5%A5%BD%E5%B7%A5%E5%85%B7%EF%BC%9Arancher

http://columns.chicken-house.net/2016/04/29/rancher-on-azure-lab/

Ubuntu16.04

I try to addhost in Rancher,but get this error

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /v1 (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f5b3588b810>: Failed to establish a new connection: [Errno 111] Connection refused',))


because the 

Host Registration URL

I use the http://localhost:8080 orginally
and the Rancher got find the top IP 192.168.1.109:8080
after that I modify the IP 192.168.1.109:8080

 just leave the 4th column blank is fine.
copy and paste to the terminal

official github
https://github.com/rancher/rancher/issues/1151



2017年4月28日 星期五

.bundle/cache/compact_index/rubygems.org error

I got this in few months, and can't find the solution.
after all, I found it. Just clean the cache. 
 
http://stackoverflow.com/questions/41472374/bundle-install-fails-permission-denied-rb-sysopen

rm -rf ~/.bundle/cache



There was an error while trying to write to
`/home/xxx/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/versions`. It is likely that you need to
grant write permissions for that path.




2017年4月27日 星期四

cs50 2016

week4
NodeList

datastructure
stack
queue

compressor

hashing table

week2
initilaize
int main(int argc, string argv[])
$ ./initials ccc  => argc ==2;
$ ./initials ccc  => argv[1]==ccc;


//這個卡了我三個小時
if(s[i] == '\0')  <--一直想這樣弄結果卡在這
if(s[i] == ' ')
{
i++;
printf("%c", toupper(s[i]));
}

http://imil.au.edu.tw/~hsichcl/TurboC/C_Unit10.htm
http://programming.im.ncnu.edu.tw/Chapter10.htm

caesar 終於卡沒那麼那麼久了  放煙火
printf("%c\n", plaintext[i]); 

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>

int main(int argc, string argv[])
{
    if (argc == 2)
    {
    string plaintext = get_string();
    int key = atoi(argv[1]);
    // printf("plaintext:");
    // printf("%s\n",plaintext);
        for(int i = 0, n = strlen(plaintext); i < n; i++)
        {
            if(isalpha(plaintext[i]))
            {  
                if(isupper(plaintext[i]))
                {
                    int upc = (plaintext[i] + key - 65) % 26 + 65;
                    printf("%c", upc);
                }else
                {
                    int lpc = (plaintext[i] + key - 97) % 26 + 97;
                    printf("%c", lpc);
                }
            }else{
                printf("%c", plaintext[i]);
            }
        }
    }
    printf("\n");
}
 

2017年4月22日 星期六

JS30

D15
localStorage

D14
    array reference, not an array copy when use 
    const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];

    // and we want to make a copy of it.
    const team = players;

JSON-is-not-Javascript-Object
http://www.fizerkhan.com/blog/posts/JSON-is-not-Javascript-Object.html

D13
滾動超過圖片一半會跑出來

D12
addEventListener的運用('keyup',(e) =>{})

D11
這句話讓我見識到chrome的強大
webkitEnterFullScreen();

D10
with shift key

D9
console.* 教學

D8
console.xxx教學

D7
canvas 畫板,很酷

D6
Ajax search
.fetch

D5
漂亮的夾頁

D4
javascript function練習

D3
圖片CSS漸變

D2
css
    transform-origin: 100%;
    transform: rotate(90deg);
    transition: all 0.05s;
    transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);


    const seconds = now.getSeconds();
    const secondsDegrees = ((seconds / 60) * 360 + 90);
    secondsHand.style.transform = `rotate(${secondsDegrees}deg)`;

Methods   setInterval

D1
Nodelist
http://www.w3school.com.cn/xmldom/dom_nodelist.asp

keys.forEach(key => key.addEventListener('transitionend', removeTransition));

2017年4月21日 星期五

rails 進階 base to_param overide the id rails

http://jacopretorius.net/2015/03/overriding-named-route-parameters-in-rails.html

https://apidock.com/rails/ActiveRecord/Base/to_param

http://ruby-journal.com/how-to-override-default-primary-key-id-in-rails/.

  get :products, path: 'products#show', param: :title

https://apidock.com/rails/v4.0.2/ActiveSupport/Inflector/parameterize


http://blog.teamtreehouse.com/conversational-and-short-urls-on-rails

http://ricostacruz.com/cheatsheets/rails-routes.html

2017年3月17日 星期五

resposive firefox is ok chrome not

I made a page with bootstrap navbar it wrok fine in firefox when the device is mobile, the navbar is collapsed, but the chrome page is same with computer view.

after all, to add this in the head tag, it will tell browers the width is the device-width

<meta name="viewport" content="width=device-width,initial-scale=1">

ubuntu 16.04 chrome crash

ubuntu下使用chrome常常用沒多久整個系統就停住,即使更新到最新版也沒有解決

在網路上找了一下其實蠻無解的,

後來終於找到方法了,去chrome的設定->進階設定

把下面的硬體加速關掉 unchekc the gpu accerlation

用到現在好像真的解決了,有遇到的人可以試看看

  1. Go to settings in chrome.
  2. Advance Setting
  3. System > Uncheck "Use hardware acceleration..."





2017年3月16日 星期四

deploy rails passenger digitalocean error

I follow the step with the pages
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/digital_ocean/nginx/oss/xenial/deploy_app.html

when all the work done, still can get start, you'll get this page.
 
 server {
    listen 80;
    server_name yourserver.com;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/myapp/code/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /path-to-ruby;  
 

 This line let me struggle 1 day 
take it away 
 }
 
 
 
 
 The Answer


http {

add this
    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /usr/local/rvm/gems/ruby-2.3.3/wrappers/ruby;


finish