Skip to content

Instantly share code, notes, and snippets.

@spajak
spajak / descriptor.py
Created June 11, 2019 17:05
Simple usage of Python 3 descriptors
class MyDescriptor:
def __set_name__(self, owner, name):
self.name = name
def __get__(self, instance, owner):
return f'Surprise from "{self.name}" descriptor'
def __set__(self, instance, value):
# You can set any property here or raise an exception to make it read only property
pass
@spajak
spajak / haraka.service
Last active December 13, 2019 16:19
Nginx, uWSGI and php-fpm, haraka systemd service units
[Unit]
Description=Haraka SMTP server
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/haraka.pid
ExecStart=/usr/bin/haraka -c /usr/local/etc/haraka
ExecStop=/bin/kill -s QUIT $MAINPID
@spajak
spajak / forking.php
Created June 11, 2019 16:35
Forking in PHP 7 done right. No zombies!!
<?php
/**
* Forking in PHP 7 done right. Requires PHP >= 7.1 and Process Control extension (pcntl)
*
* @author Sebastian Pająk
* Good article in the subject that inspired me: https://ruslanspivak.com/lsbaws-part3
*/
// Enable asynchronous signal handling (as of PHP 7.1)
@spajak
spajak / batch_cmd_arguments.cmd
Last active June 11, 2019 16:44
Batch script command line arguments variables
@echo off
rem Batch script (.bat or .cmd) command line arguments variables
rem %* - for all command line parameters (excluding the script name itself)
rem %0 - the command used to call the batch file
rem %1 - is the first command line parameter
rem %2 - is the second command line parameter, and so on till %9 (and SHIFT can be used for those after the 9th)
rem %~nx0 - the actual name of the batch file, regardless of calling method (some-batch.bat)
rem %~dp0 - drive and path to the script including trailing backslash (d:\scripts\)
@spajak
spajak / gulpfile.js
Last active June 11, 2019 16:48
Sample config for gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sasslint = require('gulp-sass-lint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
@spajak
spajak / colors.sh
Last active June 11, 2019 16:46
Linux Bash terminal colors
#!/bin/bash
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
#Background
for clbg in {40..47} {100..107} 49 ; do
@spajak
spajak / np.py
Created March 19, 2018 19:34
Napiprojekt API. Pobieranie napisów do filmu
import sys
import hashlib
import base64
import os.path
import urllib.request, urllib.parse
import xml.etree.ElementTree as ET
URL='http://www.napiprojekt.pl/api/api-napiprojekt3.php'