發表文章

PHP session_write_close()

圖片
PHP函式 php session_write_close() End the current session and store session data. session 的資料需要在 script 結束時才會儲存,所以當有2 個 script 同時執行時,後面的 script 會等前面的 script 執行完成再來跑,如果設定了  session_write_close() 就可以立即告訴程式,我後面的程序不會寫入 session 了,其他程式可以讀取 session 的內容來處理。 好處就是:程序不會被前一個 session 卡住,但是寫入 session 的行為就要很小心的處理。 範例: http://konrness.com/php5/how-to-prevent-blocking-php-requests/ 說明:  http://php.net/manual/en/function.session-write-close.php Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done. ref: http://xyz.cinc.biz/2012/01/php-session-lock.html 

RabbitMQ 實作 AMQP 的開放原始碼訊息代理軟體

圖片
RabbitMQ 是一個訊息中介軟體 (broker) 可以接受並轉發訊息,他是 AMQP 的實作。 功能類似郵局機制,類似 unix Email system。 主要處理的存儲、轉發 binary blobs of data (二進制資料) 那 AMQP 它和傳統的 SMTP 差異在哪裡??  重點在可以 非同步,並且可靠 。 ref:  http://blogs.mulesoft.com/dev/news-dev/amqp-and-the-future-of-web-messaging/   系統中的角色: 訊息發布者 publisher = 訊息消費者 consumer 訊息代理 brokers 訊息生產者 producers 訊息交換模型 (ref:  http://rabbitmq.mr-ping.com/AMQP/AMQP_0-9-1_Model_Explained.html ) 使用 RabbitMQ 的顧客  https://blog.pivotal.io/channels/data-science-pivotal Pivotal Labs 原來不只玩 big data 它是一間很有趣的公司呀!!( MADlib 是它開發中的產品..) 因為還不是很熟悉,所以放了很多參考連結: 官方網站 http://www.rabbitmq.com    in github  https://github.com/rabbitmq 官方教學  http://www.rabbitmq.com/getstarted.html  中文教學  http://rabbitmq.mr-ping.com/ WIKI 介紹 https://zh.wikipedia.org/wiki/RabbitMQ PHP 函式 http://php.net/manual/fa/book.amqp.php  PHP amqplib in GITHUB  https://github.com/php-amqplib/php-amqplib  Python 函式 https:/...

直接把 html table 轉成可以 search , sort , 翻頁的表格

一個很好用的 Jquery 套件,可以直接把 html table 轉成可以 search , sort , 翻頁的表格, 不用自己寫太多的前端網頁工作。 DataTable   https://www.datatables.net  Example: https://www.datatables.net/examples/basic_init/zero_configuration.html 刪減多餘 code 後的簡單範例: https://mtchang.github.io/test/datatables_example.html

CentOS7 Linux 安裝給 pokemon bot 使用的 proxy server

圖片
CentOS7 Linux 安裝給 pokemon 使用的 proxy server  Porxy 服務早期是因為網路頻寬小,通常在區網內把重複的流量用 proxy 來取代。 現在則變成一種可以欺騙 web server 客戶端來源 IP 的一個小技巧,有人用於當 bot 爬網站,有人用於分散流量抓迷片。而今天,我把它用來服務 pokemon bot client ,因為一個 bot 抓太慢拉!!! XDXD * 安裝及設定 Linux 的 Proxy 服務 # 安裝 squid yum install squid -y # 編輯設定檔 /etc/squid/squid.conf nano /etc/squid/squid.conf # 在這段之後 # # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS # # 放入下面三行規格, ip 請自行更動 acl mynet src 111.32.141.0/24 acl mynet src 111.32.141.0/24 http_access allow mynet # 啟動 systemctl restart squid  # 開機預設啟動 systemctl enable squid  # 確定 port 3128 是否工作 netstat -antlp | grep squid tcp6       0      0 :::3128        :::*         LISTEN      29062/(squid-1)   * 設定 pokemon bot , 這裡是以 Ar1i 開發的 PokemonGo-Bot 來當範例。 https://github.com/Ar1i/PokemonGo-Bot/tree/master/Builds-Only  Ar1i 幾乎每天都在發新的版本,也修正很多 bug ,目前用過感覺最好的 bot 。 ...

PostgreSQL 使用的 timestamp 變更 timezone 很簡單

圖片
PostgreSQL 使用的 timestamp 變更顯示的 timezone 很簡單 只要把 select 欄位後方加上  AT TIME ZONE ' EST '  就可以 這裡的  'EST' 指的是美東時間,縮寫可以參考官方說明。 https://www.postgresql.org/docs/8.1/static/datetime-keywords.html  範例SQL: SELECT id, transaction_time,to_char((transaction_time AT TIME ZONE 'CCT')  , 'YYYY-MM-DD  HH24:MI:SS' )  as cct_transaction_time,  to_char((transaction_time AT TIME ZONE 'EST')  , 'YYYY-MM-DD  HH24:MI:SS' )  as est_transaction_time   FROM root_memberdepositpassbook WHERE member_id = '45'  ORDER BY est_transaction_time DESC LIMIT 10; https://www.postgresql.org/docs/9.5/static/functions-formatting.html  關於欄位的輸出格式官方網站也有說明,可以讓你以你想的方式輸出。直接再 SQL 敘述指定就可以。 -- 北京時間 SELECT enrollmentdate, to_char((enrollmentdate AT TIME ZONE 'posix/Etc/GMT-8'),'YYYY-MM-DD HH24:MI:SS') as enrollmentdate_tz FROM root_member WHERE id = '45'; -- 美東時間 SELECT enrollmentdate, to_char((enrollmentdate AT TIME ZONE '...

Pokemon GO 有很完整的社群開發論壇及完整的 API code

圖片
pokemon go 有很完整的社群開發論壇及完整的 API code,真是令人驚豔.. https://www.reddit.com/r/pokemongodev/ 不論原生公司喜不喜歡,在 github 上面一堆延伸開發的專案,且目前更新都很頻繁,大概三天就出一個版本了... 一開始是想要參考別人 API 怎麼寫的!!! 沒想到先看到 pokemon api , 各種版本都有, 少說有 6 種以上語言支持。 PoMG API by python 2.7 https://github.com/PokeAPI/pokeapi https://pokeapi.co/docsv2/ 然後就研究了一些 bot 在作啥麼....XDXD https://www.youtube.com/watch?v=MoYjVTbLWyo ------- pokemon go 預測雷達 , 很準. 有神獸出現時只要看 Found By Trainer: (Poke Radar Prediction) 才抓,其餘都是玩家來亂的。 https://www.pokemonradargo.com/ 上面這個可能樹大招風,所以有時後會關閉服務或不正常。可以使用。 https://pkget.com/  大家找寶貝 ------- PokeMon GO 進化計算機 , 及 pokemon 介紹. 哪些是神獸也可以參考這裡。 https://pokemon.gameinfo.io/tools/evolution-calculator?hl=zh_TW ------- pokemon go 官方的 PTC 帳號註冊(Pokemon Trainer Club) https://club.pokemon.com/us/pokemon-trainer-club/sign-up/ 可以註冊一個免洗帳號,避免 google account 外流的風險。 因為他的 google  登入需要填入你的 gmaill 帳密,這很有外流的風險。 ------- 很紅的 bot NecroBot , C# console for win ------- 最初的的 NecroBot 版本, 被自殺了。 https://github...

pgadmin install in Linux Mint 17.3 ROSA

圖片
pgadmin install in Linux Mint 17.3 ROSA bash <(cat /etc/os-release; echo 'echo ${VERSION/*, /}') | head -n1 | awk '{print "deb http://apt.postgresql.org/pub/repos/apt/",tolower($1)"-pgdg main";}' > /etc/apt/sources.list.d/pgdg.list wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get install pgadmin3 三行就搞定了,去選單找找看 pgadmin 就升級為 1.21 了。 REF: http://technobytz.com/how-to-install-postgresql-9-4-in-ubuntu-linux-mint.html