This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const clientTcp = net.Socket(); | |
let intervalTcpConnect = false; | |
var isTcpConnected = false; | |
function connectTcp() { | |
clientTcp.connect({ | |
host: 'localhost', | |
port: 5060, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Small ES6 tip | |
// How to remove duplicates from array | |
// Use the spread operator to transform a set into an Array | |
const array = [1, 2, 2, 3, 3, 5, 5, 1, 1]; | |
const uniqueArray = [...new Set(array)]; | |
// uniqueArray -> [1, 2, 3, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
======== | |
Client | |
======== | |
*/ | |
const HOST = 'localhost'; | |
const PORT = 41234; | |
var dgram = require('dgram'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
======== | |
Client | |
======== | |
*/ | |
var net = require('net'); | |
const HOST = '127.0.0.1'; | |
const PORT = 8888; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateUUID() { | |
var d = new Date().getTime(); | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | |
var r = (d + Math.random() * 16) % 16 | 0; | |
d = Math.floor(d / 16); | |
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var testObj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}}; | |
function deepCopy(o) { | |
// if not array or object or is null return self | |
if (typeof o !== 'object'||o === null) return o; | |
let newO, i; | |
// handle case: array | |
if (o instanceof Array) { | |
let l; | |
newO = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ListExtension | |
{ | |
public static List<T> CloneList<T>(this List<T> list, List<T> oldlist) | |
{ | |
BinaryFormatter formatter = new BinaryFormatter(); | |
MemoryStream stream = new MemoryStream(); | |
formatter.Serialize(stream, oldlist); | |
stream.Position = 0; | |
return (List<T>)formatter.Deserialize(stream); |