Skip to content

Instantly share code, notes, and snippets.

View frentsel's full-sized avatar

Frentsel Alexandr frentsel

  • frentsel
  • Ukraine
View GitHub Profile
@frentsel
frentsel / TwoWayDataBinding.js
Last active February 10, 2017 13:03
Simple two-way data-binding
var Field = function(selector){
var el = document.querySelector(selector),
callback;
this.get = function() {
return el.value;
};
this.set = function(val) {
@frentsel
frentsel / RegExp-in-switch-case.js
Last active August 29, 2015 14:26
RegExp in Switch-Case
var age = 'think';
switch (true) {
case (/think/g).test(age):
console.log("Think!");
break;
default:
console.log("not found");
break;
};
({
css: function(el, prop){
/*return css-prop*/
},
ajax: function(options){
/*make ajax-request*/
},
init: function(name){
var cache = {};
this.getCache = function(){ return cache };
@frentsel
frentsel / sql.patch
Last active December 23, 2015 12:59
Для этого создаем временную таблицу и переносим по одной все не дублируемые записи.Дальше можно переименовать таблицы или перенести все записи из таблицы tmp_users
-- 1. Создаем временную таблицу с правильными записями
CREATE TABLE tmp_users
SELECT * FROM users AS u
GROUP BY u.login
HAVING COUNT(u.login) >= 1
-- 2. Переносим данные из tmp_users в users
-- предварительно очистив users
INSERT INTO users
SELECT * FROM tmp_users
@frentsel
frentsel / str_replace.js
Last active May 24, 2018 13:30
js analog PHP str_replace()
String.prototype.replaceAll = function(find, replace) {
if(typeof find === 'string')
return this.split(find).join(replace);
var str = this;
find.forEach(function(el, i){
str = str.split(el).join(replace[i]);
});