Skip to content

Instantly share code, notes, and snippets.

@polonskiy
polonskiy / transmission-remote-magnet.bash
Created March 24, 2018 19:05 — forked from sbisbee/transmission-remote-magnet.bash
Quick and easy way of making Chrome send bittorrent magnet links to a remote Transmission instance using its API on Ubuntu with xdg.

Quick and easy way of making Chrome send bittorrent magnet links to a remote Transmission instance using its API on Ubuntu with xdg. This method does not require modifying any system files or xdg's scripts, whereas most of the examples I found on the Internet did require such hacks.

Chrome does not handle default applications, instead relying on the OS to manage that. The default handler in Ubuntu is xdg, which maps the MIME type to the default application. Extra tooling is required because xdg requires a registered desktop file, so you can't simply give it a command to run.

Steps:

  1. Install the shell script transmission-remote-magnet ideally in /usr/local/bin: ln -s ~/src/transmission-remote-magnet.bash transmission-remote-magnet

  2. Install the desktop file, which is required for xdg to work and will likely require sudo: desktop-file-install ./transmission-remote-magnet.desktop

@polonskiy
polonskiy / encrypted-git-repo.md
Created February 7, 2018 12:13
Transparent Git Encryption

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang (geek@cerias.net). It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].

Description

When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes

@polonskiy
polonskiy / segfault-finder.php
Created August 23, 2016 12:04 — forked from lyrixx/segfault-finder.php
How to find a segfault in PHP
<?php
register_tick_function(function() {
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$last = reset($bt);
echo sprintf("%s +%d\n", $last['file'], $last['line']);
});
declare(ticks=1);
@polonskiy
polonskiy / array_of_example.php
Last active January 21, 2016 09:24 — forked from bernik/array_of_example.php
array_of realization in php
<?php
class User {
public
$name,
$lastName;
public function __construct($name, $lastName) {
$this->name = $name;
$this->lastName = $lastName;

Composer Workflow

Example of why composer.lock should be version controlled and workflow of how it can be used.

The reason we put ranges in composer.json is so that we can check for updates in our development environment and test our source code works with it BEFORE it goes into production.

The reason we have specific versions of vendors in composer.lock is so that we can version it and install the application into production environments with the versions we have tested while in development. Because of this we never run composer update on a production environment.

Creating an Application

140 byte PHP routing system.

This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.

require('route.php');

// A user profile
route('/(\w+)/profile', function($path, $user)
{

print "Hello " . $user;

<?php
class Server
{
public $master;
public $read = [];
public $write = [];
public $writeBuf = [];
public function listen($address)
@polonskiy
polonskiy / gist:6412223
Created September 2, 2013 12:13 — forked from oziks/demo.php
<?php
function flatten($array, $prefix = '') {
$result = array();
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix.$key] = $value;

Microframework

This is a PHP (5.3+) microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
  • integrated Dependency Injection and settings system
  • named patterns

140 byte PHP routing system.

This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.

require('route.php');

// A user profile
route('/(\w+)/profile', function($path, $user)
{

print "Hello " . $user;