Skip to content

Instantly share code, notes, and snippets.

View ngnguyen1's full-sized avatar

Nga Nguyen ngnguyen1

  • FPT - Silicon Labs
  • Hà Nội
  • 09:42 (UTC +07:00)
  • LinkedIn in/nga-nguyen
View GitHub Profile
@ngnguyen1
ngnguyen1 / Role
Created November 5, 2014 12:28
Role
{ "name" : "teacher", "description" : null, "created" : { "$date" : 1414991300446 }, "modified" : { "$date" : 1414991300446 }, "_id" : { "$oid" : "54570dc4a4b45b194d0b5885" } }
{ "name" : "admin", "description" : null, "created" : { "$date" : 1414991412700 }, "modified" : { "$date" : 1414991412700 }, "_id" : { "$oid" : "54570e349a721b4f4d86573f" } }
{ "name" : "teacher", "description" : null, "created" : { "$date" : 1415188791938 }, "modified" : { "$date" : 1415188791938 }, "_id" : { "$oid" : "545a11378f748c4a578be4ab" } }
@ngnguyen1
ngnguyen1 / project.js
Created November 5, 2014 15:15
project.js
var debug = require('debug')('boot:create-model-instances');
module.exports = function(app) {
var User = app.models.user;
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
var Team = app.models.Team;
User.create([
{username: 'John', email: 'john@doe.com', password: 'opensesame'},
@ngnguyen1
ngnguyen1 / index.html
Last active August 29, 2015 14:08
index file
<!DOCTYPE html>
<html>
<head>
<script src="nga.js"></script>
</head>
<body>
<div id="txtCDInfo">
<button onclick="loadXMLDoc()">Get from locations</button>
</div>
@ngnguyen1
ngnguyen1 / test.js
Created November 29, 2014 17:30
Async example
function doSomethingOnceAllAreDone(){
console.log("Everything is done.");
}
function Item(delay){
this.delay = delay;
}
Item.prototype.someAsyncCall = function(callback){
setTimeout(function(){
console.log("Item is done.");
if(typeof callback === "function") callback();
@ngnguyen1
ngnguyen1 / password.js
Created December 27, 2015 03:05 — forked from soplakanets/password.js
Password hashing for node.js
var crypto = require('crypto');
var SaltLength = 9;
function createHash(password) {
var salt = generateSalt(SaltLength);
var hash = md5(password + salt);
return salt + hash;
}
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,07,00,00,00,1d,00,38,00,38,00,1d,00,1d,e0,38,e0,38,e0,1d,e0,3a,00,01,00,01,00,3a,00,00,00,00,00
// This is comments, pls don't paste your file
// Create file named your-file.reg
// This file will swap my keys map: ESCAPE to CAPSLOCK, and control to alt keys.
// Windows Registry Editor Version 5.00 => this line to indicate that registry editor version, it's for windows 7, 8. (not sure worked in windows 10)
// Follow registry editor version line must be blank line.
Tổng hợp những kiến thức trong 2 ngày (28-29/4-2016)
Vấn đề:
Thư viện Webtorrent hiện tại chỉ support WebRTC protocol, (không support tcp/udp protocol do lý do bảo mật) điều đó có nghĩa là sẽ không thể lấy các pieces từ các client mà sử dụng giao thức tcp/udp, đồng thời có nghĩa rằng nếu trong torrent không có bất kì client nào sử dụng giao thức WebRTC thì sẽ người dùng sẽ không thể nào lấy được nội dung torrent.
Các giải quyết:
Đầu vào chúng ta là một magnetURI của một torrent mà không có client nào sử dụng giao thức WebRTC.
Ví dụ:
magnet:?xt=urn:btih:359c6570ffc6e5cd6c06e2a0bea75624ddbb7121&dn=alan.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=http%3A%2F%2Flocalh
! `xev` and `showkey` to see which keycode is pressed
!old keys
!xmodmap -pke |grep Something
!keycode 50 = Shift_L ISO_Prev_Group Shift_L ISO_Prev_Group
!keycode 62 = Shift_R ISO_Next_Group Shift_R ISO_Next_Group
!keycode 66 = Caps_Lock NoSymbol Caps_Lock
!keycode 22 = BackSpace BackSpace BackSpace BackSpace NoSymbol NoSymbol Terminate_Server
!keycode 37 = Control_L NoSymbol Control_L
%% This is the functions used to find min, max number and to calculate sum of a list without use fold.
%% find the maximum number of the list
max([H|T]) -> max2(T, H).
max2([], Max) -> Max;
max2([H|T], Max) when H > Max -> max2(T, H);
max2([_|T], Max) -> max2(T, Max).
%% fold here
fold(_, Start, []) -> Start;
fold(F, Start, [H|T]) -> fold(F, F(H,Start), T).
%% Use fold to write the map function.
map(F,L) -> fold(fun(X, Acc) -> [F(X)|Acc] end, [], L).
%% Exp: map(fun(X) -> X+1 end, lists:seq(1,3)). => [2,3,4]