Skip to content

Instantly share code, notes, and snippets.

View zmts's full-sized avatar
🇺🇦
russian warship go f*uck yourself

Sasha Zmts zmts

🇺🇦
russian warship go f*uck yourself
View GitHub Profile
@zmts
zmts / gist:e6605e6ffacdef0905bd
Last active October 28, 2015 12:22
Decorator
// https://ru.wikipedia.org/wiki/Декоратор_(шаблон_проектирования)
// Класс для последующего декорирования
function Coffee() {
this.cost = function() {
return 1;
};
}
// Decorator A
@zmts
zmts / pg-promise example select
Last active April 2, 2017 21:51
sql, postgresql, expressjs, nodejs
app.get("/pg", function(req, res) {
connection.any("SELECT * FROM people", true)
.then(function(data) {
res.format({
"application/json": function() {
res.status(200).send(data);
console.log(data);
}
});
})
// define function with two args and callback
function foo(a, b, cb) {
console.log(a + ' ' + b);
// check type of cb
if (typeof(cb) === "function") {
cb();
}
else {
console.log('error ' + cb + ' not a function');
function checkPalindrom(str) {
strLowerCase = str.toLowerCase();
var reverse = strLowerCase.split('').reverse().join('');
if (reverse === strLowerCase) {
console.log(str + ' ' + 'is Palindrom');
} else {
console.log(str + ' ' + 'is not Palindrom');
}
}
// parent class
function Animal(name) {
this.name = name;
};
Animal.prototype.getName = function() {
return console.log(this.name);
};
// child class
function Dog(name){
File -> Open Your Keymap
'atom-text-editor[data-grammar="text html mustache"]:not([mini])':
'tab': 'emmet:expand-abbreviation-with-tab'
.bw{
width: 450px;
height: 450px;
background-repeat: no-repeat;
background-image: url(http://i.imgur.com/GEJoUAB.jpg);
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%); /* IE 10-11 */
-o-filter: grayscale(100%);
@zmts
zmts / TrimSpaces
Last active September 15, 2016 09:52
Удаляем пробелы
// Удаляем пробелы в начале и конце строки, используя
// возможности библиотеки jQuery
var text1 = " a b c d e f g ";
var newText1 = $.trim(text1);
// Увидим "a b c d e f g"
// Удаляем пробелы в начале и конце строки, используя
// регулярные выражения в JavaScript (RegEx):
var text2 = " a b c d e f g ";
var newText2 = text2.replace(/(^\s+|\s+$)/g,'');
@zmts
zmts / momentjs
Created September 7, 2016 11:33
How to parse Date in MomentJS
// http://momentjs.com/docs/#/displaying/format/
// moment('InputDate', 'MaskOfInputDate').format('OutputDate')
// example
moment('27/08/2016 09:00:00 PM', 'DD/MM/YYYY mm:hh:ss A').format('DD/MM/YYYY')
@zmts
zmts / emailValidation
Last active September 15, 2016 09:49
function check(mail){
return /^[0-9a-z]([\.-]?\w+)*@[0-9a-z]([\.-]?[0-9a-z])*(\.[0-9a-z]{2,4})+$/i.test(mail)
}
console.log( check('some_name@mail.super.puper.ua') ) // >> true