Skip to content

Instantly share code, notes, and snippets.

View SVilgelm's full-sized avatar
💻
diving into the Rust && C#

Sergey Vilgelm SVilgelm

💻
diving into the Rust && C#
View GitHub Profile
@SVilgelm
SVilgelm / single_or_array.go
Last active April 7, 2023 08:41
single or array type in Go
package spec
import (
"encoding/json"
"gopkg.in/yaml.v3"
)
// SingleOrArray holds list or single value
type SingleOrArray[T any] []T

Keybase proof

I hereby claim:

  • I am SVilgelm on github.
  • I am svilgelm (https://keybase.io/svilgelm) on keybase.
  • I have a public key whose fingerprint is C08A 28D0 D765 525F E8B6 81B4 08D0 E2FF 7788 87E6

To claim this, I am signing this object:

@SVilgelm
SVilgelm / main.go
Last active June 5, 2019 04:11
go: don't defer close on writable files
// https://www.joeshaw.org/dont-defer-close-on-writable-files/
func helloNotes() error {
f, err := os.Create("/home/joeshaw/notes.txt")
if err != nil {
return err
}
defer f.Close()
if err = io.WriteString(f, "hello world"); err != nil {
return err
@SVilgelm
SVilgelm / examples.md
Last active July 22, 2019 13:16
Shell sanitizing, quoting parameters
  • Old code
    exec_cmd('ping {ip}'.format(ip=ip))
    Rewritten code
    exec_cmd(format_cmd('ping {ip}', ip=ip))
    Examples
    format_cmd('ping {ip}', ip="$(rm -rf /)")
    $ ping '$(rm -rf /)'
    ping: cannot resolve $(rm -rf /): Unknown host 
@SVilgelm
SVilgelm / neutron-clean-all.sh
Created December 4, 2015 23:48
Clean all network resources from neutron
#!/bin/bash
function get_ids {
echo `$@ --fields=id | tail -n+4 | head -n-1 | awk '{ print $2 }'`
}
function get_body {
echo `$@ | tail -n+4 | head -n-1`
}
@SVilgelm
SVilgelm / nginx.conf
Created September 28, 2015 07:55 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@SVilgelm
SVilgelm / rc.local
Created September 30, 2014 11:47
server hints
#/etc/rc.local
ipset create black_ips hash:ip
iptables -A INPUT -m set --match-set black_ips src -j DROP
grep "Failed password for" /var/log/auth.log | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort | uniq -c | awk '$1 > 5 { print $2}' | xargs -I{} ipset add black_ips {}
@SVilgelm
SVilgelm / send_email.py
Last active April 21, 2020 00:21
send email
#!/usr/bin/env python2
from email import header
from email.mime import audio
from email.mime import application
from email.mime import image
from email.mime import multipart
from email.mime import text
import logging
import mimetypes
@SVilgelm
SVilgelm / instruction.txt
Created June 26, 2014 10:56
PPTP VPN on Ubuntu 12.04 Example
Here is a quick tutorial to set up a basic PPTP VPN server on Ubuntu 12.04.
Install Necessary Packages
$ aptitude install ppp pptpd
Configure DNS Servers to Use When Clients Connect to this PPTP Server
$ nano /etc/ppp/pptpd-options
Modify OR Add the following lines in end
ms-dns 8.8.8.8
@SVilgelm
SVilgelm / decorator.py
Last active May 26, 2017 18:03
Python decorator
import functools
def dec(func=None):
if func is None:
return lambda f: dec(f)
@functools.wraps(func)
def wrapper(*args, **kwargs):
print('wrapper')
return func(*args, **kwargs)