Skip to content

Instantly share code, notes, and snippets.

View avesus's full-sized avatar
🎯
Focusing

Brian Cannard avesus

🎯
Focusing
View GitHub Profile
@avesus
avesus / errors-handling.md
Last active August 29, 2015 14:22
Errors Handling & Code Organisation
  • Use http://sweetjs.org/ to implement condition checkers. Монада maybe на Promise'ах (строчка return default;):
newAsyncFunc().then(function(success) {
    return anotherAsync();
  }, function(error) {
    return default;
  }).then(function(success) {
    return yetAnotherAsync();
 }, function(error) {
@avesus
avesus / bloop.js
Last active August 29, 2015 14:25 — forked from jlongster/bloop.js
bloop
(function() {
// Do not use this library. This is just a fun example to prove a
// point.
var Bloop = window.Bloop = {};
var mountId = 0;
function newMountId() {
return mountId++;
}
@avesus
avesus / postgres_slave_promote.md
Last active August 29, 2015 14:25 — forked from bartek/postgres_slave_promote.md
What to do when promoting a postgresql slave to master

This example is based on having a cascading setup, where you have a single master, a single "primary" slave, and cascading slaves which are being replicated from the primary slave. For an example of this setup, check out http://bartek.im/blog/2012/12/04/postgresql-92-streaming-primer.html

On the existing master, if accessible, stop postgres.

$ sudo service postgresql stop

And better to be safe than sorry. We can't have two masters running. (I only use this in an automated script. If you're doing this manually, you'd know if it was shutoff)

$ kill -9 `sudo cat /var/lib/postgresql/9.2/main/postmaster.pid | head -n 1` &> /dev/null
@avesus
avesus / mithril-touch.js
Last active August 29, 2015 14:27 — forked from webcss/mithril-touch.js
mithril-touch, consume touch and mouse events evenly with mithril
/*****************************************
/* DOM touch support module
/*****************************************/
if (!window.CustomEvent) {
window.CustomEvent = function (event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
};
@avesus
avesus / animator.js
Last active August 29, 2015 14:27 — forked from barneycarroll/animator.js
A factory for decorating Mithril modules / views / elements with incoming and outgoing animations.
var animating = false;
// Define an animator consisting of optional incoming and outgoing animations.
// alwaysAnimate is false unless specified as true: false means an incoming animation will only trigger if an outgoing animation is also in progress.
// forcing dontClone to true means the outward animation will use the original element rather than a clone. This could improve performance by recycling elements, but can lead to trouble: clones have the advantage of being stripped of all event listeners.
function animator( incoming, outgoing, alwaysAnimate, dontClone ){
// The resulting animator can be applied to any number of components
return function animate( x, y, z ){
var config;
var parent;
@avesus
avesus / mjsx_loader.js
Last active August 29, 2015 14:27 — forked from Naddiseo/mjsx_loader.js
Babel plugin to compile jsx to mithril compiled code. Released under BSD 3-clause
/* global require, module */
var isString = require('lodash/lang/isString');
var htmlTags = (
'^(html|base|head|link|meta|style|title|address|article|' +
'body|footer|header|h[1-6]|hgroup|nav|section|dd|div|dl|dt|' +
'figcaption|figure|hr|li|main|ol|p|pre|ul|a|abbr|b|bdi|bdo|br|' +
'cite|code|data|dfn|em|i|kbd|mark|q|rp|rt|rtc|ruby|s|samp|small|span|strong|sub|' +
'time|u|var|wbr|area|audio|img|map|track|video|embed|iframe|object|param|source|' +
'canvas|noscript|script|del|ins|caption|col|colgroup|table|tbody|td|tfoot|th|thead|tr|' +
@avesus
avesus / mithril-patch.es6.golfed.js
Last active August 29, 2015 14:27
Patches Mithril to accept components as well as strings
// If you need a license, this is under the ISC license.
// In golfed ES6, just because I could... (84 characters)
this.m=(o=>Object.assign((...a)=>(typeof a[0]=='string'?o:o.component)(...a),o))(m);
@avesus
avesus / view.jsx
Last active August 29, 2015 14:27 — forked from insin/view.jsx
JSX version of a Mithril TODO example - try it with http://facebook.github.io/react/jsx-compiler.html
/**
* JSX version of https://github.com/jpmonette/todomvc-mithril/blob/1d627f1d5dc0890d0a99cdcb16d09387f68f6df0/js/views/todo-view.js
* Assumes the use of the vanilla JSX Transformer and an "mshim" object to translate tag calls to the format m() expects.
* @jsx mshim
*/
'use strict';
var m = require('mithril')
@avesus
avesus / inlineedit.js
Last active August 29, 2015 14:27 — forked from StephanHoyer/inlineedit.js
Inline edit mithril component
'use strict';
var m = require('mithril');
var extend = require('lodash').extend;
var setFocus = require('../util/viewhelper').setFocus;
var keymage = require('keymage');
function noop(){}
function addClass(el, className) {