Skip to content

Instantly share code, notes, and snippets.

@A
A / onAvailable.js
Last active December 16, 2015 18:20 — forked from mistakster/gist:4193053
onAvailable: Executes the supplied callback when the item with the supplied id is found.
(function (window, document) {
function onLoad(callback) {
if (document.readyState === "complete") {
setTimeout(callback, 1);
} else if (document.addEventListener) {
window.addEventListener("load", callback, false);
} else {
window.attachEvent("onload", callback);
}
@A
A / getDeclinedNumeralStringForRussian.js
Last active December 17, 2015 14:39
Написал JavaScript функцию, которая правильно склоняет единицы измерения числительных, например «1 час», «11 минут», «21 грамм», «5 толстых шлюх».
/**
* Функция возвращает строку с числом и названием единиц измерения (например '1 час', '11 минут', '21 грамм', '5 толстых шлюх').
* @param {Number} number Число
* @param {String} nominative Название единиц измерения в иминительном падеже и ед.числе (час, минута)
* @param {String} genitive Название единиц измерения в родительном падеже и ед.числе (часа, минуты)
* @param {String} genitive_pl Название единиц измерения в родительном падеже и ед.числе (часов, минут)
* @param {Bool} showZero Показывать ли результат, если number = 0
* @return {String} '5 минут', '11 часов', '1 грамм'
*/
var getDeclinedNumeralStringForRussian = function (number, nominative, genitive, genitive_pl, showZero) {
@A
A / shortcode-params.js
Created May 23, 2013 14:44
Combine user attributes with known attributes and fill in defaults when needed.
/* exported shortcodeParams */
/**
* Combine user attributes with known attributes and fill in defaults when needed.
*
* The defaults should be considered to be all of the attributes which are
* supported by the caller and given as a list. The returned attributes will
* only contain the attributes in the defaults list.
*
* If the params list has unsupported attributes, then they will be ignored and
@A
A / MyModule.js
Last active December 17, 2015 23:39
Пришел к такой структуре js-модулей. Создаю инстанс так new MyModule({ // Здесь передаю параметры });
/* global shortcodeParams */
/* exported MyModule */
var MyModule = function (params) {
'use strict';
var defaults = {
};
➜ diskUtil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *500.1 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS shuvalov 499.2 GB disk0s2
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *120.0 GB disk1
1: EFI 209.7 MB disk1s1
@A
A / _settings.styl
Created August 31, 2013 14:34
Выглядит полезным. По крайней мере, в отношении шрифтов.
// -------------------------------------------------------
// Roots global settings variables
// -------------------------------------------------------
// font options (add your own!)
helvetica-neue = "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif
helvetica = "Helvetica Neue", Helvetica, Arial, sans-serif
georgia = Georgia, Cambria, "Times New Roman", Times, serif
lucidia-grande = "Lucida Grande", Tahoma, Verdana, Arial, sans-serif
monospace = unquote("'Bitstream Vera Sans Mono', Consolas, Courier, monospace")
@A
A / Gruntfile.js
Last active December 22, 2015 17:19
'use strict';
var path = require('path');
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var folderMount = function folderMount(connect, point) {
return connect.static(path.resolve(point));
};
module.exports = function (grunt) {
// grunt || grunt browser — разработка в браузере
@A
A / inheritance.js
Created September 14, 2013 12:05
ZOMG TEH INHERITANCE!
'use strict';
var shrtAttrs = require('shortcode-params');
var util = require('util');
var SuperModule = function (params) {
this.attributes = shrtAttrs(this.defaults, params);
//
// Time offset stuff
//
if (vk.time && !browser.opera_mobile) setTimeout(function() {
var t = new Date(), time = [0, t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes()];
if (time[1] == 1 && vk.time[1] == 12) {
vk.time[1] = 0;
} else if (time[1] == 12 && vk.time[1] == 1) {
time[1] = 0;
} else if (time[1] > vk.time[1] + 1 || vk.time[1] > time[1] + 1) {
@A
A / NODE_ENV.sh
Last active December 26, 2015 15:29
Почему стоит писать NODE_ENV=production
# create app
npm i -g express
express test
cd test
npm i
# test w/o NODE_ENV
node app.js > /dev/null &
pid=$!
ab -n 1000 -c 100 -k -q http://127.0.0.1:3000/ | grep "Requests per" | cut -d ' ' -f 7