Skip to content

Instantly share code, notes, and snippets.

View asduser's full-sized avatar

Network Engineer asduser

View GitHub Profile
@asduser
asduser / nextPrevItem.js
Last active October 11, 2016 21:24
A special feature to find next\prev item in array only when item has value. Will be skipped all unnecessary items by their id's.
// Go to the next item.
function nextIndex(index, arr){
var item = null;
var minI = 0;
var i = index;
while (i < arr.length) {
i++;
if (i == arr.length) { i = minI; }
if (arr[i].id && arr[i].val) { item = arr[i]; break;}
}
@asduser
asduser / url_parameters.js
Created August 28, 2016 21:20
Get all URL parameters.
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
// we'll store the parameters here
var obj = {};
// if query string exists
if (queryString) {
@asduser
asduser / callable_function_es5.js
Created August 25, 2016 19:20
A way to modify an internal function checking.
//
// ES5 IMPLEMENTATION
//
function applyFilter(binary){
return function(a,b){
return binary(a,b);
}
}
function add(a,b){ return a + b; }
function mult(a,b){ return a * b }
@asduser
asduser / consumer.py
Created August 17, 2016 18:53
A simple code, which explains the process of entity status changing by using of private and public methods.
#!/usr/bin/env python
class Fruit:
def __init__(self):
self.__state__ = False
def isEaten(self):
return self.__state__
@asduser
asduser / closest-number.js
Last active July 24, 2016 16:54
Closest number in array
/*
* @param num {number} - required digit
* @param arr {array} - input set of digits
* @returns {number} - closest item
*/
function closest (num, arr) {
try {
if(isNaN(num)){
throw new Error("The 1st argument is not a number.");
@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>() { };
@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 / 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
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 / 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},