Skip to content

Instantly share code, notes, and snippets.

@imposibrus
imposibrus / autossh.service
Created March 25, 2022 14:28
Simple SSH-tunnel in SystemD
[Unit]
Description=Keeps a tunnel to 'server.com' open
After=network-online.target ssh.service
[Service]
# starting in user-mode:
User=user
ExecStart=/usr/bin/ssh -q -Nt -o ControlMaster=no -o ControlPath=/tmp/no -o ExitOnForwardFailure=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -p 22 -l user server.com -R 2224:127.0.0.1:22 -i /home/user/.ssh/id_rsa
# Restart every >2 seconds to avoid StartLimitInterval failure
@imposibrus
imposibrus / ControlEdit.ts
Created August 25, 2021 08:04
vue-class-component example from 2017
import Vue from 'vue';
import Component from 'vue-class-component';
@Component({
name: 'control-edit',
props: {
actionName: {
type: String,
default: '',
},
@imposibrus
imposibrus / Community.vue
Last active August 23, 2021 08:48
Vue.js example components
<template>
<div>
<section class="page-content__content page-content__wrap-items">
<div class="community page-content__community">
<div class="community__head">
<figure class="community__cover">
<img :src="community.image_big_url" class="community__cover-img" alt="">
</figure>
<div class="community__head-panel">
<div class="community__head-avatar">
@imposibrus
imposibrus / http.js
Created July 6, 2021 09:57
Node.js servers one-liners
require('http').createServer((req, res) => {console.log(req.headers);res.writeHead(200);res.end('Hello, World!');}).listen(3000, '0.0.0.0')
@imposibrus
imposibrus / bash.sh
Last active January 19, 2021 13:28
Parse Traefik logs, extract response time and calc percentiles
export REQUEST_NAME='getMessages'; \
docker-compose logs traefik | grep $REQUEST_NAME | grep 'HTTP/1' | \
awk -F ' - - ' '{print $2}' | awk '{print $13}' > "/tmp/logs_$REQUEST_NAME.log" && \
sort -V "/tmp/logs_$REQUEST_NAME.log" | python3 /tmp/percentiles.py
# exmaple output from `docker-compose logs`:
# traefik | 192.168.1.100 - - [19/Jan/2021:08:30:56 +0000] "POST /chat/getUsersByIds HTTP/1.0" 200 60 "-" "-" 170636628 "middleware@docker" "h2c://10.27.3.25:80" 27ms
#
@imposibrus
imposibrus / my.cnf
Last active April 13, 2019 16:04
macOS Mysql config
# /usr/local/etc/my.cnf
[mysqld]
general-log-file = /usr/local/var/mysql/mysql.log
general-log = 1
log-output = file
sql_mode = ''
log_error = /usr/local/var/mysql/error.log
max_connections = 500
@imposibrus
imposibrus / send-magic-packet.sh
Last active September 4, 2022 04:15 — forked from SteveMarshall/send-magic-packet.sh
Wake-On-Lan Magic Packet using netcat in bash
#!/usr/bin/env bash
mac_address=$1
# Strip colons from the MAC address
mac_address=$(echo $mac_address | sed 's/://g')
broadcast=$2
port=9
nc_args="-w1 -u"
@imposibrus
imposibrus / index.js
Created January 22, 2016 12:31
EGTS_SR_POS_DATA parser (EGTS_TELEDATA_SERVICE)
const net = require('net');
var getBits = (octet) => {
var bits = [];
for (var i = 7; i >= 0; i--) {
var bit = octet & (1 << i) ? 1 : 0;
bits.push(bit);
}
return bits;
@imposibrus
imposibrus / feedback.js
Last active December 15, 2015 19:12
Tests
var server = require('../../../bin/www'),
request = require('supertest'),
models = require('../../../models');
describe('Feedback', function() {
it('should all fields be required', function(done) {
request(server)
.post('/api/feedback')
.expect('Content-type', /application\/json/)
@imposibrus
imposibrus / Collection.js
Created November 8, 2015 21:00
JS ActiveRecord
import Dispatcher, {EventObject} from "Dispatcher";
/**
* Items collection
*/
export default class Collection {
static E_ADD = 'add';
static E_REMOVE = 'remove';
static E_CHANGE = 'change';