Skip to content

Instantly share code, notes, and snippets.

View asduser's full-sized avatar

Network Engineer asduser

View GitHub Profile
@asduser
asduser / TypeScript_sample.js
Created March 16, 2016 20:24
TypeScript sample.
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
// Enumeration to define a Person gender.
var Gender;
(function (Gender) {
Gender[Gender["Male"] = 0] = "Male";
Gender[Gender["Female"] = 1] = "Female";
@asduser
asduser / callback_sample.js
Created March 28, 2016 21:32
Simple JavaScript callback.
const users = [
{Name: "Peter", Age: 30, Id: 1},
{Name: "Bob", Age: 20, Id: 2},
{Name: "Jack", Age: 25, Id: 3}
];
class userManager {
constructor() {
this.getById = (id, callback) => {
let result = users.find( (u) => u.Id == id );
/**
* This class provides a functional to find a point inside a specific figure.
* First of all you have to define a figure coordinates.
* Then use an appropriate method "check( point )", which will return a result.
*/
class PointManager {
constructor(setList) {
this.setX = [];
this.setY = [];
@asduser
asduser / performanceTest1a.js
Last active July 2, 2021 10:33
Performance difference between array.find vs array.indexOf. Result: indexOf is faster ;)
// ES5
var list = [];
for (var i =0, len = 500000; i < len; i++) {
list.push(i);
}
console.time("test");
repeater(20, {callback: test1, value: 499999, list: list} );
console.timeEnd("test");
@asduser
asduser / delegate_1.cs
Created March 30, 2016 21:25
How does delegate work? Explanation via C#. Example based on abstract user account in bank.
using System;
namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
// Create a new account instance with initial amount.
Account acc = new Account(500);
@asduser
asduser / mockData.js
Created April 8, 2016 09:11
Often used "mock" data to work with Angularjs.
var users = [
{"FullName": "User one", "Email": "[email protected]", "Phone": "1234567890", "Id": 1},
{"FullName": "User two", "Email": "[email protected]", "Phone": "1234567890", "Id": 2},
{"FullName": "User three", "Email": "[email protected]", "Phone": "1234567890", "Id": 15},
{"FullName": "User four", "Email": "[email protected]", "Phone": "1234567890", "Id": 14},
{"FullName": "User five", "Email": "[email protected]", "Phone": "1234567890", "Id": 12},
{"FullName": "User six", "Email": "[email protected]", "Phone": "1234567890", "Id": 8},
{"FullName": "User seven", "Email": "[email protected]", "Phone": "1234567890", "Id": 16},
{"FullName": "User eight", "Email": "[email protected]", "Phone": "1234567890", "Id": 9},
{"FullName": "User nine", "Email": "[email protected]", "Phone": "1234567890", "Id": 25},
@asduser
asduser / README.md
Last active May 24, 2016 11:08
jQuery "ng-repeat" functionality.

ng-repeat using jQuery

Simple implementation Angular's ng-repeat behaviour.

jsfiddle#1 - just elements repeating

jsfiddle#2 - repeating with hardcodded click

jsfiddle#3 - repeating with click

@asduser
asduser / README.md
Last active April 16, 2016 20:56
How does a bit shift work?

Explanation about bit shift.

@asduser

Used languages: JavaScript, C#.

Shift to right.

Number: 93.

@asduser
asduser / README.md
Created May 20, 2016 19:35
Simple sms-form (html + jquery)

Message block which provides a basic "sms-message" functionality via HTML.

  1. If message length < 1, a button will be disabled.
  2. Displaying a message status (length/maxLength).
  3. Dynamic message status changing.

Demo

See jsfiddle

@asduser
asduser / c#_dictionary_vs_list.cs
Last active June 5, 2016 20:34
Comparing performance difference for Dictionary type & IList Collection type.
using System;
using System.Linq;
using System.Collections.Generic;
namespace Program {
public static void Man(string[] args) {
Random rnd = new Random();
Dictionary<string, long> dic = new Dictionary<string, long>() { };