Skip to content

Instantly share code, notes, and snippets.

@snnwolf
snnwolf / dataclass_sample.py
Created October 15, 2021 16:05 — forked from decatur/dataclass_sample.py
Use Python dataclass to autogenerate timestamp and sequence id on an object.
from dataclasses import dataclass, field
from itertools import count
from datetime import datetime
counter = count()
@dataclass
class Event:
message: str
@snnwolf
snnwolf / Dockerfile
Created February 24, 2020 10:43
Docker файл для прода, напр, flask
FROM python:3.6.3-alpine3.6
COPY requirements.txt /
RUN apk --update add --virtual .base build-base && \
apk add --no-cache postgresql-dev && \
pip install -r requirements.txt && \
rm requirements.txt && \
apk del .base && \
adduser -D -S -u 1000 -G users -h /home/app app && \
rm -rf /tmp/* /var/tmp/* /usr/share/man /tmp/* /var/tmp/* \
@snnwolf
snnwolf / add-remove-event.js
Last active April 20, 2018 06:54
Подписаться/отписаться на/от события
var addEvent = function(el, e, callback, capture) {
if (!!window.addEventListener) {
el.addEventListener(e, callback, !!capture);
} else {
el.attachEvent("on" + e, callback);
}
},
removeEvent = function(el, e, callback, capture) {
if (!!window.addEventListener) {
el.removeEventListener(e, callback, !!capture);
@snnwolf
snnwolf / modx-snippets.php
Created February 13, 2018 21:13 — forked from fomigo/modx-snippets.php
Useful snippets for MODX Revo
Snippet: [[SnippetName]]
Chunk: [[$ChunkName]]
System Setting: [[++SettingName]]
TV: [[*fieldName/TvName]]
Link tag: [[~PageId? &paramName=`value`]]
Placeholder: [[+PlaceholderName]]
<?php
@snnwolf
snnwolf / sendMail.snippet.php
Last active June 17, 2020 10:24
Сниппет для #modx для отправки уведомления на мыло с прикреплением файла
<?php
// взято здесь https://ilyaut.ru/reposts/sending-mail-through-modmail/
/**
* Перед использованием установить переменные: emailsender, site_name
* Опции:
* [$html] отправить в виде html, если не задан, останется текст
* $address строка адресов через ","
* $subject
* [$subject_prefix] префикс для сообщения напр, "[site_name] Вам письмо"
* $message
@snnwolf
snnwolf / Вывод количества товаров в категории.php Вывод количества товаров в категории minishop2Сниппет получает сумму всех товаров в категории, с учетом мультикатегорий MS2. Можно указать нужную категорию параметром $parent. #modx
<?php
if (empty($parent)) {$parent = $modx->resource->id;}
$pids = array_merge(array($parent), $modx->getChildIds($parent));
$ids = array();
$q = $modx->newQuery('msProduct');
$q->where(array('class_key' => 'msProduct','parent:IN' => $pids,'published' => 1,'deleted' => 0));
$q->select('`msProduct`.`id`');
if ($q->prepare() && $q->stmt->execute()) {
$ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
@snnwolf
snnwolf / .babelrc
Created January 5, 2018 23:29 — forked from koddr/.babelrc
Webpack 3 config for simple Django/Flask project with Autoprefixer, PostCSS, SCSS style files, Vue.js and Babel
{
"presets": ["@babel/preset-env"]
}
@snnwolf
snnwolf / run-multiple-redis-instances.md
Created April 11, 2016 06:48 — forked from jarvys/run-multiple-redis-instances.md
run multiple redis instances on the same server for centos
  • create a new redis .conf file
$ cp /etc/redis.conf /etc/redis-xxx.conf
  • edit /etc/redis-xxx.conf, illustrated as below
...
@snnwolf
snnwolf / slack_notification.php
Created April 6, 2016 11:26 — forked from alexstone/slack_notification.php
Fire a Slack Notification via CURL
<?php
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
public static function slack($message, $room = "engineering", $icon = ":longbox:") {
$room = ($room) ? $room : "engineering";
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => $message,
@snnwolf
snnwolf / sugar.coffee
Created April 1, 2016 09:36
Синтетический сахар для coffee. Не забываем про http://sugarjs.com/
# немного синтетики
# fmt = "<p>{0} {1} (<a href='mailto:{2}'>{2}</a>)</p>"
String::format = (args...) ->
@replace /{(\d+)}/g, (match, number) ->
if number < args.length then args[number] else match