Skip to main content

Posts

Showing posts from May, 2019

Chrome youtube iframe magnific popup autoplay

https://github.com/dimsemenov/Magnific-Popup/issues/725 Yah MP have patterns Late to the party, in case someone needs to use the actual embed URL for Magnific, here is my process: Write a function that gets the input URL, checks it's format and then ensures that the /embed/ url is returned. In Magnific markup always use the processed URL which is in the embed format. Add the following patterns to magnific, to essentially use the input URL as the url without processing it further: // Video popup, Backend enforces embed URL before it gets here.     $('.js-popup-video').magnificPopup({         type: 'iframe',         iframe: {             patterns: {                 youtube: {                     index: 'youtube.com/',                     id: function (url) { return url },                     src: '%id%'                 },                 vimeo: {                     index: 'vimeo.com/',                     id: function (url

Focus vs Attention

https://monq.com/eo/physiology/focus-and-attention-same/ Complete attention https://jkrishnamurti.org/content/complete-attention Many time I've confused or hard to focus on some work. And may be this is the root cause: What do we mean by attention? Is there attention when I am forcing my mind to attend? When I say to myself, “I must pay attention, I must control my mind and push aside all other thoughts,” would you call that attention? Surely that is not attention. What happens when the mind forces itself to pay attention? It creates a resistance to prevent other thoughts from seeping in; it is concerned with resistance, with pushing away; therefore it is incapable of attention. That is true, is it not? To understand something totally you must give your complete attention to it. But you will soon find out how extraordinarily difficult that is, because your mind is used to being distracted, so you say, “By Jove, it is good to pay attention, but how am I to do it?” That is,

Observer 2

Simple Sample http://www.java2blog.com/2013/02/observer-design-pattern-in-java.html Apply for Collision detection: When Product Samsung available, it notify all Person John and Aaron subcribed to it. When new box is generated (simple box jump game), it notify all walls in the boards. But the important behavior is that the box will running. When box contact wall, it collidate. Then box (or wall) notify game manager that box has clash (die/disappear). Wall ~ Person subcribe to Product new. Product ~ Box (running box/static box/ jumping box). All wall as Person has been notified when new product available or new box appear, running. But when box colidate, only colidated wall need to know about clash ? (beside Game manager) State of the box (x,y position, direction jump...) need to notify for all wall in game board when box moving ? Always notify wall when box has tiny change position is awkward ? Action Jump() is not simple https://softwareengineering.stackexchange.

Gdx drawing multiple sprites

http://stackoverflow.com/questions/24425595/drawing-multiple-sprites-in-libgdx Scale sprite http://stackoverflow.com/questions/21382913/how-to-resize-a-sprite-in-libgdx So when we check collision, are the sprite's width, height changed or it not depend on scale ratio ? Aspect ratio http://stackoverflow.com/questions/9198932/how-to-deal-with-different-aspect-ratios-in-libgdx

Gdx Screens

http://www.pixnbgames.com/blog/libgdx/how-to-manage-screens-in-libgdx/ I will update later. I will follow this guide later. This example has HTTPRequest http://stackoverflow.com/questions/25837013/switching-between-screens-libgdx Trong sample cubocy hay Pax Britana đều có cách manage screens. Cubocy thì implememt tương tự link đầu.

Gdx vector move item

RTFM - Read the fucking manuals. http://stackoverflow.com/questions/17694076/moving-a-point-vector-on-an-angle-libgdx // Declared as fields, so they will be reused Vector2 position = new Vector2(); Vector2 velocity = new Vector2(); Vector2 movement = new Vector2(); Vector2 touch = new Vector2(); Vector2 dir = new Vector2(); // On touch events, set the touch vector, then do this to get the direction vector dir.set(touch).sub(position).nor(); Which will give you a normalized direction vector from the position to the touch point. You can then scale it to the speed you want to move, then use it to update your position. velocity = new Vector2(dir).scl(speed); And on each frame, do something like this movement.set(velocity).scl(deltaTime); position.add(movement); Here's how it would look like in a full class: class Game extends ApplicationAdapter {     Vector2 position = new Vector2();     Vector2 velocity = new Vector2();     Vector2 movement = new Vector2()

GIT quản lý nhánh release, hotfix, trace thay đổi cho branch release

Flow release của cty hơi suck. SVN. GIT. Search gg xem flow git với release branch ntn. http://stackoverflow.com/questions/16386323/following-git-flow-how-should-you-handle-a-hotfix-of-an-earlier-release git checkout 6.0 git checkout -b support/6.x git checkout -b hotfix/6.0.1 ... make your fix, then: git checkout support/6.x git merge hotfix/6.0.1 git branch -d hotfix/6.0.1 git tag 6.0.1 or using git flow commands git flow support start 6.x 6.0 git flow hotfix start 6.0.1 support/6.x ... make changes then: git flow hotfix finish 6.0.1 Bash trace lịch sử change của branch: http://stackoverflow.com/questions/2514172/listing-each-branch-and-its-last-revisions-date-in-git List branch sắp theo ngày mod: http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit Basic Usage: git for-each-ref --sort=-committerdate refs/heads/ # or using git branch (since version 2.7.0) git branch --sort=-committerdate (DESC)

Using Git with pre-SVN project

Found the solution from Version Control with Git book. Page 295. Instead of use local - master branch, have to checkout remote branch git checkout remote/master (Detach HEAD) git merge --no-ff master (merge the local master) git svn dcommit git push origin (update to git Repository) This model is for one person who will merge back to Subversion repository while the other work on pure Git OR pure Subversion. With this way, The Git Users can use Git without Merging problem.

Host web on github

https://github.com/hmfaysal/Notepad https://github.com/barryclark/jekyll-now Vim improved viim https://www.safaribooksonline.com/blog/2014/11/23/way-vim-ide/ https://www.openshift.com/ https://www.heroku.com/ Clone martin fowler theme https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/

Socket.IO chat group, room ...

Việc quản lý list user online/socketID ... trong 1 mảng hoặc DB rất quan trọng trong việc xác định tin nhắn sẽ được gửi cho ai. http://www.codershood.info/2016/01/24/sending-message-specific-user-socket-io/ Chuẩn của nó ra phải dùng socket room. http://www.tamas.io/advanced-chat-using-node-js-and-socket-io-episode-1/ Nhưng do chưa quen nên tạm dùng trick, vẫn emit all xong dùng 1 vài key để filter lúc append msg vô list. DB cũng vậy dùng key để insert vô DB theo room_id.

Aptible note 2

https://community.aptible.com/t/identifying-users-in-an-aptible-ssh-context/194 https://security.stackexchange.com/questions/31024/encrypt-data-within-mobile-app-and-send-to-web-service Some QA survey from  https://www.hhs.gov/hipaa/for-professionals/compliance-enforcement/audit/questionnaire/index.html?language=es Docker Aptible nginx reveal open-ssl support (normally as linux support latest ?) https://github.com/aptible/docker-nginx SSL vs TLS https://www.fastmail.com/help/technical/ssltlsstarttls.html Mã hóa đường truyền khác j mã hóa data (content email chẳng hạn) ? Vụ audit: có mã hóa mail authen ko ? (có => what version?) TLS and/vs SSL https://en.wikipedia.org/wiki/Transport_Layer_Security http://frodo.looijaard.name/article/sendmail-using-tls-authentication Sample network diagram http://akioz.com/network-architecture-diagram/ There're many app to draw Net diagram. MS Visio can but not widely used ? So hard 2 find sample file ? So much information

Express JS router

http://stackoverflow.com/questions/43061791/how-to-combine-express-and-angular-routes Back end routing : Routes defined to fetch/update data. Front end routing : Routes defined as per the page which shall be shown to user. So lets say we have two pages , home page and profile page so, front end routes will have two pages "/home" loading home page "/profile" loading profile now on each of the page, you would need to show some data inside the html page, for which you make routes : "/getHomePageData" route to return some news feed (lets say) "/getProfilePageData" route to return some user related information http://stackoverflow.com/questions/14934452/how-to-get-all-registered-routes-in-express http://stackoverflow.com/questions/35749288/separate-file-for-routes-in-express console.log(app._router.stack); // Express >= 4.5.x https://scotch.io/tutorials/keeping-api-routing-clean-using-express-routers Sender's name, just in

The NBA will use Israeli WSC’s AVGEN (Automatic Video Generator) and Clipro technology to automatically generate customized highlights in near real-time.

NBA, giải bóng rổ nhà nghề Mỹ, với giá trị thương hiệu và độ phủ sóng rất lớn, từ gần 2 năm nay đã quyết định sử dụng công nghệ AVGEN (Automatic Video Generator) của cty Israel có tên là WSC (http://wsc-sports.com/) để tạo ra các đoạn highlights (video tổng hợp các tình huống đáng chú ý) cho các trận đấu bóng rổ một cách tự động, và gần như theo thời gian thực. Không những vậy, AVGEN còn có thể tạo ra những highlights riêng cho từng cầu thủ trong từng trận đấu hay trong cả một mùa bóng (rất có giá trị trong việc định giá, mua bán và trả lương cho cầu thủ). Các bạn có thể đọc thêm tại các links sau: www.usatoday.com/…/nba-provide-customized-video-h…/76929162/ http://pr.nba.com/nba-wsc-sports-technologies-partnership/ Và bây giờ, lại một cty Israel cung cấp Articoolo, giải pháp tạo ra những bài viết tự động, dựa trên các từ khóa cho trước, và hoàn toàn không trùng lặp với bất kỳ bài nào đã có (unique). Các bạn có thể trải nghiệm thử tại đây (có preview kết quả): http://articoolo.com

NodeJS Authentication, JWT security

https://security.stackexchange.com/questions/51294/json-web-tokens-jwt-as-user-identification-and-authentication-tokens http://stackoverflow.com/questions/27301557/if-you-can-decode-jwt-how-are-they-secure https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/ https://news.ycombinator.com/item?id=11895440  (Master piece) Thêm 1 giải thích cơ chế truyền SESSION_ID từ client lên Server: Consider the first case. Each client gets a random ID that lasts for the duration of the session - which could be several days if you like. Then you store the information relevant to that session somewhere server side. It could be in a file or a database. Let's suppose you pass the ID via a cookie but you could use the URL or an HTTP header Tức là ngoài dùng cookie, Browser/Client có thể dùng HTTP header hay URL (GET?). https://softwareengineering.stackexchange.com/questions/298973/rest-api-security-stored-token-vs-jwt-vs-oauth

Notes some node command, tool, package config on Ubuntu, Windows.

List package installed with depth. npm list -g --depth=0 sudo npm list -g --depth=0 npm install package on VirtualBox Shared folder. Instead I clone source code to another repo (not shared folder) in virtual linux. Then install package, copy whole node_modules/package_name to shared project repo dir. Because of I run node server on Linux guest. If I run on Host Windows then I re-install package on Windows. Because some package are OS depend ie. bcrypt...

Another Nodejs validator

router.post('/register', function(req, res) {   req.check('name', 'Name must be Filled in').notEmpty();   req.check('email', 'Email must be Filled in').notEmpty();   req.check('email', "Invalid Email").isEmail();   req.check('password', 'Password Field must be Filled in').notEmpty();   req.check('password', 'Passwords do not Match').equals(req.body.password2)   var errors = req.validationErrors();   if(errors) res.send(errors)   else{     var newUser = new User({       name: req.body.name,       email: req.body.email,       password: req.body.password,       info: req.body.user_bio     });     User.createUser(newUser, function(err, user){             if(err) throw err;     });     res.redirect('../')   } })

Express-JWT and jsonwebtoken

Express-JWT is just a library for Express that validates/signs json web tokens whcih can be used with the express web server (middleware). JsonWebTokens is just another implementation of json web tokens. There are many other JWT token libraries you can implement with node. Express-jwt is just one of those. They both essentially do the same thing and you can use either or. None are built on top of each other, they are build using the JWT standard. Choose the one which best suites your requirements. https://stackoverflow.com/questions/20612275/how-to-use-req-session-data-in-an-other-javascript-file-expressjs This is not possible with your current setup without a lot of hacking. Each session is reliant on the user's SID found in the request's cookie. Thus, the session is strongly coupled to the request object. You will have to find a clever way to initialize your  game.js  module through middleware. Something like: var Game = require ( './game' ); // -- Place t

Socket.IO performance

https://stackoverflow.com/questions/18907591/socket-io-server-performance-and-bandwidth-usage API HTTP vs WebSocket https://blogs.windows.com/buildingapps/2016/03/14/when-to-use-a-http-call-instead-of-a-websocket-or-http-2-0/#YtK4rHfLG7Jsl7DA.97

Git gc

https://stackoverflow.com/questions/2116778/reduce-git-repository-size https://superuser.com/questions/204564/how-can-i-find-files-that-are-bigger-smaller-than-x-bytes find . -type f -size +4096c You can rewrite history in Git - don't let Trump do it for real! Trump's administration has lied consistently, to make people give up on ever being told the truth. Don't give up: https://www.rescue.org/topic/refugees-america

DNS, CNAME, A record ...

https://en.wikipedia.org/wiki/List_of_DNS_record_types#A https://en.wikipedia.org/wiki/CNAME_record https://www.aptible.com/support/topics/enclave/how-do-i-use-my-domain-apex-on-aptible/ https://serverfault.com/questions/613829/why-cant-a-cname-record-be-used-at-the-apex-aka-root-of-a-domain

Aptible two

https://www.aptible.com/support/topics/enclave/direct-docker-image-deploy/ https://www.aptible.com/support/toolbelt/ https://www.aptible.com/support/topics/enclave/dockerfile-build-deploy/ https://www.aptible.com/support/topics/enclave/how-do-i-setup-an-apex-redirect-using-aws/ https://www.aptible.com/support/topics/enclave/how-does-the-maintenance-page-url-config-setting-work/

The POST/redirect pattern

https://stackoverflow.com/questions/9107226/how-to-end-an-express-js-node-post-response You can use res.end and pass in a string that you want to be sent to the client: res.end('It worked!'); Alternatively, you could render a view and then end the response: res.render('blah.jade'); res.end(); All that said, redirecting the client is actually the best practice. It makes it so that when they hit the back button in their browser, they can move back seamlessly without getting any "POST required" popups or the like. This is the POST/redirect pattern and you can read more about it at http://en.wikipedia.org/wiki/Post/Redirect/Get.

Sendmail status

Huge mail queue Deferred After clear queue server back to lighting fast. It seem to be I/O problem. Because of no mem or CPU usage. remove file in long list dir: https://stackoverflow.com/questions/11289551/argument-list-too-long-error-for-rm-cp-mv-commands Or simple remove abc* abd* ... https://serverfault.com/questions/615116/abnormal-sendmail-activity-using-up-the-server-memory-on-my-ubuntu-12-04-server

jwt express

/*requiring node modules starts */ var express = require("express"), router = express.Router(); var app = module.exports = express(); var http = require('http').Server(app); var io = require("socket.io")(http); var Session = require('express-session'); var cookieParser = require('cookie-parser'); /*requiring node modules ends */ var jwt    = require('jsonwebtoken'); // used to create, sign, and verify tokens var bcrypt = require('bcryptjs'); // the session is stored in a cookie, so we use this to parse it app.use(cookieParser()); var Session = Session({     secret:'secrettokenhere',     saveUninitialized: true,     resave: true }); io.use(function(socket, next) {     Session(socket.request, socket.request.res, next); }); app.use(Session); // app.use(Session({secret:'davzk#1234', cookie:{maxAge:7200}})); var sessionInfo = {}; /* requiring config file */ var config =require(

Docker one

http://tatiyants.com/devops-is-ruining-my-craft/ First time I disagree with an article from ThoughtWorks. Monoliths are not a bad design, not at all. The solution to all the problems you raised has been created more than 20 years ago, it is called object oriented programming. You expediate this solution with statements such as "while this... In practice we see...". And I think this is unfair because the only reason most messy monoliths are messes is because most of the developers DO NOT KNOW Object-Oriented Programming. If their learned OOP the same way you ask them to learn micro-services, things would be different. People list OOP on their CV but are not able to model a OOP domain model. I've interviewed many people and most of them had no clue. They only know about textbook situations, and can't leverage OOP in a real world project. I developped a very complex system, with many modules and dependencies. When I left the company, I wrote up a documentatio

Hapi one

https://www.pluralsight.com/blog/software-development/node-web-frameworks http://blog.pipecandy.com/chose-loop-sails-meteor/ https://medium.com/@tkssharma/hapi-js-vs-loopback-for-writing-enterprise-application-b86c86ccfb22 https://www.reddit.com/r/node/comments/31tv6m/hapi_vs_kraken_vs_loopback/ https://news.ycombinator.com/item?id=13067731

Git rebase

https://stackoverflow.com/questions/33942588/difference-between-rebase-master-and-rebase-onto-master-from-a-branch-deri Bear with me for a while before I answer the question as asked. One the earlier answers is right but there are labeling and other relatively minor (but potentially confusing) issues, so I want to start with branch drawings and branch labels. Also, people coming from other systems, or maybe even just new to revision control and git, often think of branches as "lines of development" rather than "traces of history" (git implements them as the latter, rather than the former, so a commit is not necessarily on any specific "line of development"). ... [wall of text]

Note GDX best practices

https://stackoverflow.com/questions/17199449/is-calling-libgdx-spritebatch-begin-and-end-method-multiple-times-expensive https://github.com/mattdesl/lwjgl-basics/wiki/Batching-Rectangles-and-Lines GDX AI https://gamedevelopment.tutsplus.com/series/understanding-steering-behaviors--gamedev-12732 https://github.com/libgdx/gdx-ai https://github.com/libgdx/gdx-ai/wiki/Formation-Motion https://stackoverflow.com/questions/7223723/in-libgdx-how-do-i-get-input-from-the-back-button

Macus Anthony giải thích pattern

https://blog.ircmaxell.com/2011/03/follow-up-dependency-injection-analogy.html

Re install stock ROM Samsung Galaxy S7 G930T

https://www.sammobile.com/firmwares/galaxy-s7/SM-G930T/ Mình muốn root máy android để làm 1 số việc, vd sửa file hosts bên android để test một số domain ảo (Virtual Host). Ô nào làm web chắc biết cái này. Nhiều app như Google SSO, Facebook .. đòi 1 domain = tên chứ ko dùng IP được. Việc này m ko chắc nhưng đại khái là máy Android cần sửa được file hosts để tiện testing và debug. Sau khi root con S7 thường T-Mobile nó chạy chậm vlon. Ko có vân tay. Sau khi fix vân tay, twik các kiểu vẫn chậm. Mình tính cho về room mặc định hoặc 1 cái rom nhẹ nhất. Room gốc có nhiều cái ko muốn như facebook ko xóa được, mấy app T-Mobile, Samsung pay ... éo bao h dùng. https://forum.xda-developers.com/galaxy-s7/development/rom-s7-rom-v1-0-t3356197

MVC on client side

https://medium.freecodecamp.org/is-mvc-dead-for-the-frontend-35b4d1fe39ec https://staltz.com/unidirectional-user-interface-architectures.html M. Fowler nói MVC thực ra cái C ko quan trọng. Đây là pattern được nói nhiều nhất và hiểu sai nhiều nhất. Khi dùng bên client side sẽ expose nhiều vđ để hiểu rõ hơn MVC. Chapter 14. Web Presentation Patterns cuốn Patterns of the Enterprise Application Architecture. https://en.wikipedia.org/wiki/Component-based_software_engineering https://medium.com/@dan.shapiro1210/understanding-component-based-architecture-3ff48ec0c238 Post này nhiều hình dễ hình dung https://staltz.com/unidirectional-user-interface-architectures.html