Skip to content

Instantly share code, notes, and snippets.

@polymorphm
polymorphm / port_switch.js
Last active August 29, 2015 14:22
Javascript for automatic switch between portable versions of template
// -*- mode: js; coding: utf-8 -*-
(function ($) {
'use strict'
var module = {
view_mode_get: function() {
var width = $(window).width()
if (width < 768) {
@polymorphm
polymorphm / data-find-and-replace.py
Last active August 29, 2015 14:19
find some text words in files and replace it to other words
#!/usr/bin/env python3
# -*- mode: python; coding: utf-8 -*-
assert str is not bytes
import sys
import os, os.path
import csv
import itertools
import random
@polymorphm
polymorphm / wsgi.py
Last active August 29, 2015 14:19
WSGI router (by host) example
#!/usr/bin/env python3
# -*- mode: python; coding: utf-8 -*-
assert str is not bytes
import my_example_1_wsgi as _my_example_1_wsgi
import my_example_2_wsgi as _my_example_2_wsgi
import my_example_3_wsgi as _my_example_3_wsgi
_application_by_host_dict = {
@polymorphm
polymorphm / to-test.c
Created December 17, 2014 06:01
test for catch infinite freezing (on TCP-sockets by default) on GNU/Linux
// -*- mode: c; coding: utf-8 -*-
//
// $ gcc -Wall -Werror -o to-test to-test.c && sudo ./to-test
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <arpa/inet.h>
#include <netdb.h>
@polymorphm
polymorphm / tprint.lua
Last active August 29, 2015 14:08
dump table (in lua)
local function tprint(tbl, indent, depth)
if indent == nil then indent = 0 end
if depth == nil then depth = 4 end
for k, v in g.pairs(tbl) do
local formatting = g.string.rep(' ', indent) .. g.tostring(k) .. ': '
if g.type(v) == 'table' then
if indent < depth then
g.print(formatting)
@polymorphm
polymorphm / ssh-proxy.service
Created October 26, 2014 15:29
example of ~/.config/systemd/user/ssh-proxy.service .. run it as: systemctl --user start ssh-proxy
[Unit]
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/ssh -o ServerAliveInterval=60 -NfD 1080 MY_SUPER_USER_NAME@MY_SUPER_SERVER_NAME
Restart=on-failure
RestartSec=10s
[Install]
@polymorphm
polymorphm / smartctl-Samsung-P3-Portable.txt
Created October 7, 2014 19:31
# smartctl -d sat -x /dev/sdb
[regular-user@localhost ~]$ sudo -i
[sudo] password for regular-user:
[root@localhost ~]# smartctl -x /dev/sdb
smartctl 6.3 2014-07-26 r3976 [x86_64-linux-3.16.3-1-ARCH] (local build)
Copyright (C) 2002-14, Bruce Allen, Christian Franke, www.smartmontools.org
/dev/sdb: Unknown USB bridge [0x04e8:0x61c8 (0x1301)]
Please specify device type with the -d option.
Use smartctl -h to get a usage summary
Способы самоубийства
1. Броситься под поезд
Вpемя: Секунды, или, если не повезет, - часы.
Доступность: Везде, где есть высокоскоpостные железные доpоги.
Hадежность: Зависит от Вашей сноpовки и скоpости поезда. Решайтесь на декапитацию.
Пpимечания: Веpоятно, наилучшим способом является положить шею на pельсы, тогда колесо поезда пеpебьет Вам позвоночник (и искалечит Вас). Скоpостные поезда пpи тоpможении пpоходят еще около километpа, поэтому найдите кpутой повоpот.
2. Самосожжение
Вpемя: От секунд до дней.
@polymorphm
polymorphm / proxy.pac
Last active August 29, 2015 14:03
proxy auto-config (PAC) file -- for regular usage
// -*- mode: js; coding: utf-8 -*-
//
// ``local_proxy`` it is -- ssh -o ServerAliveInterval=60 -NfD 1080 [email protected]
//
// ``tor_proxy`` it is -- tor proxy
function FindProxyForURL (url, host) {
var local_proxy = 'SOCKS5 127.0.0.1:1080'
var tor_proxy = 'SOCKS5 127.0.0.1:9050'
assert str is not bytes
def js_unicode_escape(unicode_str):
assert isinstance(unicode_str, str)
return ''.join(('\\u{:04x}'.format(ord(char)) for char in unicode_str))
print(js_unicode_escape('фигня'))