Skip to content

Instantly share code, notes, and snippets.

@jmas
jmas / Arr.js
Last active August 29, 2015 14:06
Array extended with methods .on(), .trigger(), .walk() and throw event "change" when array is mutated
var
arrayPop = Array.prototype.pop,
arrayPush = Array.prototype.push,
arrayReverse = Array.prototype.reverse,
arrayShift = Array.prototype.shift,
arraySort = Array.prototype.sort,
arraySplice = Array.prototype.splice,
arrayUnshift = Array.prototype.unshift;
var Arr = function() {
@jmas
jmas / List.js
Last active August 29, 2015 14:06
Component List. Is an example of using Arr.js. Require micromustache template engine, throttle.js utility.
var List = function(data, el, itemTamplate) {
if (! data instanceof Arr) {
throw new Error('data should be an instance of Arr');
}
if (! el instanceof HTMLElement) {
throw new Error('el should be an instanceof of HTMLElement');
}
if (typeof itemTamplate !== 'string') {
var navItems = new Arr(
{
name: 'Home',
path: '/'
},
{
name: 'About Us',
path: '/aboutus',
active: true
},
@jmas
jmas / Db.php
Last active August 29, 2015 14:08
<?php
namespace Db;
class Db {
private $connection;
public function __construct(\PDO $connection) {
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
router.post('/upload',
[ multer({
dest: path.join(__dirname, '..', config.imagesUplodsPath),
rename: function (fieldname, filename) {
return filename.replace(/\W+/g, '-').toLowerCase() + Date.now()
}
}) ],
function(req, res, next) {
res.json({
success: true,
// passport
passport.use(new LocalStrategy(
function(username, password, next) {
userService.findByUsername(username)
.then(function(user) {
if (! user) {
return userService.save({
username: username,
password: password
});
@jmas
jmas / gist:1653578572d96b60ddd5
Created April 29, 2015 05:07
Tiny javascript observable
function observable(obj) {
var listeners = {};
//
obj.on = function(name, handler) {
if (! (name in listeners)) {
listeners[name] = [];
}
listeners[name].push(handler);
return this;
};
@jmas
jmas / gist:6d6574ac413855911716
Last active August 29, 2015 14:23
Very simple javascript list class
var DataList = function(el, data, itemTpl, populateItemDataFn) {
if (! (el instanceof Node)) {
throw new Error('el should be an Node.');
}
if (! (data instanceof Array)) {
throw new Error('data should be an Array.');
}
if (typeof itemTpl !== 'string') {
throw new Error('itemTpl should be an String.');
}
@jmas
jmas / nginx
Created October 18, 2015 09:08 — forked from serhiinkh/nginx
map $status $loggable {
~^[2,3] 0;
default 1;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name ~^(www\.)?(?<domain>.+?).loc$;
{
"presets": ["es2015", "react"]
}