Skip to content

Instantly share code, notes, and snippets.

@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'
@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 / 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 / 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 / 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 / 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 / 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 / fib.py
Created June 11, 2019 17:07
Fibonacci sequence iterator in Python
class Fib:
"""Iterator that yields numbers in the Fibonacci sequence"""
def __init__(self, max):
self.max = max
def __iter__(self):
self.a = 0
self.b = 1
return self
@spajak
spajak / php-error-logging.php
Last active June 30, 2019 12:55
PHP 7 runtime errors/exceptions handling done right
<?php
/**
* Simple, custom, bulletproof PHP 7 runtime errors/exceptions handling done right (I hope so :).
* By handling I mean logging to systemd journal or stderr, and die if any exception,
* error, warning, and even notice or strict occurs. This is not all-in-one
* or an ultimate solusion, but a good base to start with.
* Logs go to stderr or systemd journal (recommended, but optional). Systemd extension
* for PHP can be found at https://github.com/systemd/php-systemd
*/
@spajak
spajak / entware-ng.sh
Last active June 19, 2019 10:12
Bootstrap Entware-ng on Synology DS
#!/bin/bash
# Script installs Entware-ng (https://github.com/Entware/Entware-ng)
# on Synology DSM 6.2 under /opt directory.
# Must be run with sudo. Can be used as a scheduled task on system boot.
printf -- "---------------------------\n"
printf -- "| Installing Entware-ng.. |\n"
printf -- "---------------------------\n"