Skip to content

Instantly share code, notes, and snippets.

View larchanka's full-sized avatar
👋
Hi there

Mikhail Larchanka larchanka

👋
Hi there
View GitHub Profile
@larchanka
larchanka / uniqid.js
Last active October 27, 2019 08:51
JavaScript function that copies functionality of PHP's 'uniqid'.
(function () {
this.uniqid = function (pr, en) {
var pr = pr || '', en = en || false, result;
this.seed = function (s, w) {
s = parseInt(s, 10).toString(16);
return w < s.length ? s.slice(s.length - w) : (w > s.length) ? new Array(1 + (w - s.length)).join('0') + s : s;
};
result = pr + this.seed(parseInt(new Date().getTime() / 1000, 10), 8) + this.seed(Math.floor(Math.random() * 0x75bcd15) + 1, 5);
@larchanka
larchanka / browserTransform.js
Last active December 27, 2015 11:19
Function `browserTransform` detects css-transforms' support in browser and returns css-property, else it returns false.
(function () {
this.browserTransform = function () {
if ('OTransform' in document.body.style)
return '-o-transform';
else if ('webkitTransform' in document.body.style)
return '-webkit-transform';
else if ('mozTransform' in document.body.style)
@larchanka
larchanka / findEntity.js
Last active August 29, 2015 13:56
Function allows to find entity in array/object by key and value. @param `keyObj` – key and value, i.e. {id:10}.
Object.prototype.findEntity = function(keyObj) {
var arr = this, p, key, val, ret;
for (p in keyObj) {
if (keyObj.hasOwnProperty(p)) {
key = p;
val = keyObj[p];
}
}
for (p in arr) {
if (p == key) {
@larchanka
larchanka / hashcode.js
Last active January 12, 2018 14:50
JavaScript: Java String.hashCode() implementation. Source: http://goo.gl/Hyt1ku
String.prototype.hashCode = function() {
var hash = 0;
try {
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
@larchanka
larchanka / YAR.js
Last active August 29, 2015 13:57
Yet Another Random
var YAR = function(nseed) {
var seed, constant = Math.pow(2, 13) + 1,
prime = 37,
maximum = Math.pow(2, 50);
if (nseed) {
seed = nseed;
}
if (seed == null) {
seed = (new Date()).getTime();
}
{
"// my options for SublimeLinter " : "//",
"jshint_options" : {
"boss": true,
"browser": true,
"curly": false,
"devel": true,
"eqeqeq": false,
"eqnull": true,
<!-- HTML code -->
<video id="player" x-webkit-airplay="allow" class="player">
<source src="http://techslides.com/demos/sample-videos/small.webm" type="video/webm">
<source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
<source src="http://techslides.com/demos/sample-videos/small.3gp" type="video/3gp">
</video>
<div id="play-controls">
<button type="button" id="mute"><i class="fa fa-volume-up fa-lg"></i></button>
// Detect if AirPlay is available
// Mac OS Safari 9+ only
if (window.WebKitPlaybackTargetAvailabilityEvent) {
video.addEventListener('webkitplaybacktargetavailabilitychanged', function(event) {
switch (event.availability) {
case "available":
airPlay.style.display = 'block';
break;
default:
@larchanka
larchanka / stringToColor.js
Last active February 23, 2021 10:22
Function converts string to HEX-color
const stringToColor = (str) => {
let hash = 0;
let color = '#';
let defaultColor = '#333333';
let i;
let value;
let strLength;
if(!str) {
return defaultColor;