Skip to content

Instantly share code, notes, and snippets.

View dmjcomdem's full-sized avatar
🎯
Focusing

Dimonskiy dmjcomdem

🎯
Focusing
View GitHub Profile
@dmjcomdem
dmjcomdem / generateSnils.js
Last active September 4, 2017 10:16
Generate snils function
function generateSnils() {
let snilsText;
let hash;
let leadZero = hash => (hash < 10 ? '0' : '') + hash;
function calculateSnilsHash(snils){
let snilsTextNumbers = snils.replace(/\D/g,'');
if (!snilsTextNumbers.match(/^\d{9}/)) return -1;
@dmjcomdem
dmjcomdem / validationSnils.js
Last active September 7, 2017 09:58
Validation Snils
// :: string => false|true
function validationSnils(snils) {
var leadZero = function(hash) {
var hashNumber = Number(hash);
return (hashNumber < 10 ? '0' : '') + hashNumber;
}
// input :: "111-111-111 11" => "11111111111"
var snilsTextNumbers = snils.replace(/\D/g,'');
@dmjcomdem
dmjcomdem / unicodeCharacters.js
Last active September 7, 2017 07:17
Unicode characters displayed in HTML and CSS
'•'.charCodeAt().toString(16) // HTML::(&#x2022) CSS::(\2022)
String.fromCharCode(0x2022); // '•'
@dmjcomdem
dmjcomdem / rgb2hex.js
Created September 18, 2017 13:02
Function to convert hex format to a rgb color
function rgb2hex(rgb = 'rgba(1, 155, 255)') {
return rgb.match(/(\d+)/ig).reduce((result, item) => {
return result += ('0' + parseInt(item,10).toString(16)).slice(-2);
}, '#')
}
rgb2hex() // "#019bff"
@dmjcomdem
dmjcomdem / center-img.css
Created September 24, 2017 08:50
Centering a picture in a block
div {
width: 400px;
height: 400px;
margin: 100px auto;
border: 1px solid #000;
position: relative;
}
img {
position: absolute;
@dmjcomdem
dmjcomdem / createObject.js
Created September 29, 2017 08:05
Example work constructor class
function Todo(title, completed = false) {
let object = {};
object.__proto__ = Todo.prototype;
this = object;
return this;
}
@dmjcomdem
dmjcomdem / encapsulation.js
Last active October 3, 2017 08:02
example encapsulation on js
const TodoList = (function() {
/*
* todos[{id, title, completed}, ...]
*/
let todos = [];
return class {
constructor() {
this.init();
}
@dmjcomdem
dmjcomdem / _.sh
Last active October 11, 2017 04:03
npm view
npm view typescript versions --json
@dmjcomdem
dmjcomdem / whichTransitionEvent.js
Created October 11, 2017 09:59
Detect the supported event property name
function whichTransitionEvent(){
var t,
el = document.createElement("fakeelement");
var transitions = {
"transition" : "transitionend",
"OTransition" : "oTransitionEnd",
"MozTransition" : "transitionend",
"WebkitTransition": "webkitTransitionEnd"
}
@dmjcomdem
dmjcomdem / renameKey.js
Created October 23, 2017 12:38
Object Rename Key
if (old_key !== new_key) {
Object.defineProperty(o, new_key, Object.getOwnPropertyDescriptor(o, old_key));
delete o[old_key];
}