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 / 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]);
});
@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
({
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 / 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;
};
@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 / Pattern module.js
Created August 5, 2015 07:51
Simple example of pattern "module" with import of extentions
var $scope = (function($){
var _this = {
name: 'Alex'
};
return {
get: function(prop){
return _this[prop];
},
set: function(prop, val){
return _this[prop] = val;
@frentsel
frentsel / Remove element from array.js
Last active August 29, 2015 14:27
Remove element from array
Array.prototype.remove = function(id){
return this.splice(id, 1);
}
var a = ["a","b","c","d"];
a.remove(2);
console.log(a);
// ["a", "b", "d"]
@frentsel
frentsel / cookieClass.js
Created August 18, 2015 08:24
Cookie module
var _cookie = {
getCookie: function (name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
},
setCookie: function (name, value, options) {
options = options || {};
@frentsel
frentsel / Pattern Mediator.js
Last active February 10, 2017 05:56
Pattern Meditor
var player = {
play: function(music){
console.info('player plaing: ', music);
}
};
var search = {
items: {
a: 'ABBA',
b: 'Boney M',
@frentsel
frentsel / isMobile.js
Created September 14, 2015 15:25
isMobile.js
var isMobile = function(){
return /Mobi|Mini|Symbian|SAMSUNG|Nokia|BlackBerry|Series|Bada|SymbOS|PLAYSTATION/g
.test(navigator.userAgent.toString());
};