Skip to content

Instantly share code, notes, and snippets.

@Kolenov
Kolenov / RandomNumInRange.js
Created February 24, 2017 20:50
Get a random number in a specific range
var x = Math.floor(Math.random() * (max - min + 1)) + min;
@Kolenov
Kolenov / RandomItemFromArray.js
Created February 24, 2017 20:52
Get a random item from an array
var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119];
var randomItem = items[Math.floor(Math.random() * items.length)];
@Kolenov
Kolenov / MaxMinInArrayOfNumbers.js
Created February 24, 2017 20:56
Get the max or the min in an array of numbers
var numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411];
var maxInNumbers = Math.max.apply(Math, numbers);
var minInNumbers = Math.min.apply(Math, numbers);
@Kolenov
Kolenov / SwapTwoVariables.js
Created February 24, 2017 21:21
Swap two variables
var a = 1; var b = 2; [a,b] = [b,a];
@Kolenov
Kolenov / Iterator.js
Created February 26, 2017 17:22
Custom Iterator
Object.defineProperty(myObject, Symbol.iterator, {
enumerable: false,
writable: false,
configurable: true,
value: function () {
var obj = this;
var idx = 0;
var ks = Object.keys(obj);
return {
next: function () {
@Kolenov
Kolenov / Vector.js
Created February 27, 2017 21:06
Vector for 2d space
/**
* A vector for 2d space.
* @param {integer} x - Center x coordinate.
* @param {integer} y - Center y coordinate.
* @param {integer} dx - Change in x.
* @param {integer} dy - Change in y.
*/
function Vector(x, y, dx, dy) {
// position
this.x = x || 0;
@Kolenov
Kolenov / jQueryPubSub.js
Created March 12, 2017 00:05
jQuery Observer Pattern
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
// Usage
document.on( 'tweetsReceived', function(tweets) {
//perform some actions, then fire an event
$.publish('tweetsShow', tweets);
});
@Kolenov
Kolenov / index.js
Created March 12, 2017 16:58
Array methods
function forEach(arr, func){
"use strict";
for (var i=0, len = arr.length; i<len; i++){
arr[i] = func(arr[i]);
}
}
function every(arr, func){
"use strict";
var res = null;
@Kolenov
Kolenov / smb.conf.ini
Created July 21, 2017 19:40 — forked from raspi/smb.conf.ini
FreeBSD ZFS Samba 4 config with recycle and read/write optimizations example
# Samba 4 config example
# Connected to existing remote Samba 4 Active Directory Directory Controller
# ZFS pool @ /storage
# Network is 192.168.101.0/24
# Samba is installed with:
# pkg install samba42
# and then joined to existing AD with:
# samba-tool domain join <params>
# After this /usr/local/etc/smb4.conf is edited and restarted with /usr/local/etc/rc.d/samba_server restart
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmit": true,