Skip to content

Instantly share code, notes, and snippets.

@sunsongxp
sunsongxp / fedora_install_python3.md
Created November 7, 2022 13:49 — forked from zobayer1/fedora_install_python3.md
Install Python 3.6, 3.7, 3.8 in your Fedora system

Python 3.9 comes as a default with Fedora 34. However, sometimes you may wish to install older versions for development and test purposes. Apart from groupinstall command, these instructions work for CentOS and REHL systems as well.

Prerequisites

Install python development dependencies.

sudo dnf groupinstall "Development Tools"
sudo dnf install python3-devel openssl-devel zlib-devel bzip2-devel sqlite-devel libffi-devel

Note: You will need to rebuild and reinstall if you install new source or development libraries for python. Do not create or modify symlinks for python, python3, etc, as that may and will break many dependent libraries in your system.

@sunsongxp
sunsongxp / GitConfigHttpProxy.md
Created October 18, 2022 12:05 — forked from evantoli/GitConfigHttpProxy.md
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@sunsongxp
sunsongxp / README.md
Created September 1, 2022 04:32 — forked from djfdyuruiry/README.md
WSL 2 - Enabling systemd

Enable systemd in WSL 2

This guide will enable systemd to run as normal under WSL 2. This will enable services like microk8s, docker and many more to just work during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

  • To enable systemd under WSL we require a tool called systemd-genie

  • Copy the contents of install-sg.sh to a new file /tmp/install-sg.sh:

    cd /tmp
@sunsongxp
sunsongxp / snat_dnat_advantech.md
Created July 6, 2022 08:23 — forked from tomasinouk/snat_dnat_advantech.md
examples of SNAT, DNAT with iptables for Advantech, Conel routers, with comments (probably will work on other routers where iptables can be manipulated, care needs to be taken on applying these commands after reboot).

Some examples of SNAT, DNAT with iptables with comments

mainly used in start-up script

How to test 'safely'

When we play with iptables aka firewall we might end up in situation, where we execute rule, which has unforseen impact - lock yourself out. Recovering from this situation is necessity.

How to:

  • Enable reboot via SMS.
  • Test all commands in shell first before putting them into Start-up script. This way the command will be wiped out, when unit is rebooted.

masquarade all outgoing packets to be WLAN0 IP

@sunsongxp
sunsongxp / epoll.go
Created July 6, 2022 07:57 — forked from Lisprez/epoll.go
Golang example for using epoll
package main
import (
"fmt"
"net"
"os"
"syscall"
)
const (
@sunsongxp
sunsongxp / systemd_service_restart_forever.service
Created April 26, 2022 09:47
This systemd service configuration will ensure that your service will attempt to restart your service FOREVER instead of the systemd default of 5 failed retries within 10 seconds and then giving up forever.
# This systemd service configuration will ensure that your service will
# attempt to restart your service FOREVER instead of the systemd default
# of 5 failed retries within 10 seconds and then giving up forever.
[Unit]
Description=MY AMAZING SERVICE
After=multi-user.target
# NOTES ABOUT THE StartLimitBurst OPTION:
# systemd default is StartLimitBurst=5 (give up after 5 failed attempts)
#!/usr/bin/python3
# Quick Sort 快速排序
# 基于《算法导论》第七章
import random
A = []
for i in range(1000000):
A.append(random.randint(0, 999999))
@sunsongxp
sunsongxp / inventory2json.py
Last active November 27, 2018 17:07 — forked from sivel/inventory2json.py
Ansible inventory to dynamic inventory JSON output, accepts all inventory input formats
import sys
import json
from ansible.parsing.dataloader import DataLoader
try:
from ansible.inventory.manager import InventoryManager
A24 = True
except ImportError:
from ansible.vars import VariableManager
@sunsongxp
sunsongxp / tmux-cheatsheet.markdown
Created November 16, 2018 15:39 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@sunsongxp
sunsongxp / README.md
Created October 25, 2018 05:06 — forked from smoser/README.md
ubuntu-auto-install: install a ubuntu image with kvm

Ubuntu Auto Install

This allows user to do automated installation of ubuntu. Provided here a a few different files/scripts for making this easier.

I've used this to verify that d-i kernel and initramfs from -proposed work as shown in bug 1511497.

The provided 'preseed' below can be used as a fully automated installation of ubuntu. Boot with qemu like:

note python web server is useful for this (python -m SimpleHTTPServer 9999)