Skip to content

Instantly share code, notes, and snippets.

View serhatates's full-sized avatar
🎯
Focusing

Serhat Ates serhatates

🎯
Focusing
View GitHub Profile
const net = require('net');
const clientTcp = net.Socket();
let intervalTcpConnect = false;
var isTcpConnected = false;
function connectTcp() {
clientTcp.connect({
host: 'localhost',
port: 5060,
});
// 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]
@serhatates
serhatates / client.js
Last active December 13, 2018 11:46
Server - Client UDP [node.js]
/*
========
Client
========
*/
const HOST = 'localhost';
const PORT = 41234;
var dgram = require('dgram');
@serhatates
serhatates / client.js
Last active September 8, 2021 14:31
Server - Client TCP [node.js]
/*
========
Client
========
*/
var net = require('net');
const HOST = '127.0.0.1';
const PORT = 8888;
@serhatates
serhatates / generate-uuid.js
Created December 13, 2018 10:44
Generate uuid
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);
});
}
@serhatates
serhatates / deep-copy.js
Last active December 13, 2018 11:11
Deep Copy(Clone) arrays, objects, null, strings, numbers, (no Date)
// 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 = [];
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);