Skip to content

Instantly share code, notes, and snippets.

View mortymacs's full-sized avatar

Morteza NourelahiAlamdari mortymacs

View GitHub Profile
@mortymacs
mortymacs / main.go
Created August 3, 2022 21:17 — forked from llonchj/main.go
Proof of concept
package main
import (
"fmt"
"net/http"
"github.com/gocolly/colly"
)
type MyCollector struct {
@mortymacs
mortymacs / 1.srp.py
Created June 26, 2022 09:34
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):

Install dependencies

apt-get install gcc-arm-linux-gnueabihf qemu

Prepare work directory

mkdir qemu-arm-sandbox && cd qemu-arm-sandbox
@mortymacs
mortymacs / cross-compile-go-arm64.md
Created April 16, 2022 15:44 — forked from conoro/cross-compile-go-arm64.md
Cross-compiling Golang for ARM64 (aarch64) e.g. Pine64 on Fedora AMD64
  • Install Go for Linux the usual way on your main Linux box:
cd
wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
tar -zxvf go1.6.2.linux-amd64.tar.gz
sudo mv go /usr/local/
export GOROOT=/usr/local/go
mkdir -p ~/gitwork/go/src
mkdir ~/gitwork/go/bin
@mortymacs
mortymacs / unixhttpc.go
Created March 30, 2022 21:09 — forked from teknoraver/unixhttpc.go
HTTP over Unix domain sockets in golang
package main
import (
"context"
"flag"
"fmt"
"io"
"net"
"net/http"
"os"
@mortymacs
mortymacs / nvramDir.md
Created October 23, 2021 18:05
libvirt nvram storage location

NVRAM storage in libvirt

Libvirt stores pflash/nvram files for privliged users in /var/lib/libvirt/qemu/nvram/ this is a copy of the template var file that is read only. OVMF uses these files to store information such as boot information. The template inforamtion was uesed to be configured in /etc/libvirt/qemu.conf but was moved to json files. [https://bugs.archlinux.org/task/64175]

Location of master nvram file This configuration option is obsolete. Libvirt will follow the QEMU firmware metadata specification to automatically locate firmware images. See docs/interop/firmware.json in the QEMU source tree. These metadata files are distributed alongside any

@mortymacs
mortymacs / gist:e553bb645c4385f61e9579f8f73146f3
Created August 31, 2021 12:03 — forked from julianlam/expose-directory-on-host-to-lxc-container.md
Exposing a directory on the host machine to an LXC container

Exposing a directory on the host machine to an LXC container

  1. Log into the container and create an empty directory, this will be the mount point
  2. Log out and stop the container.
  3. Open to your container's config file
    • For regular LXC containers: /var/lib/lxc/mycontainer/config
    • For unprivileged LXC containers: $HOME/.local/share/lxc/mycontainer/config
  4. Add a new line above the lxc.mount directive, that follows the format below. Substitute proper paths as necessary:
    • lxc.mount.entry = /path/to/folder/on/host /path/to/mount/point none bind 0 0
  • Both of these paths are relative to the host machine.
/**
* Using a single integer to represent multiple permissions
* based on binary values using bitwise operators
*
* & bitwise AND - if both the top and bottom bit are 1, result is 1
* | bitwise OR - if either the top and bottom bit or both are 1, result is 1
* ^ bitwise XOR - if only one of the bits are 1, result is 1
* 0101
* 0100 & = 0100
*
@mortymacs
mortymacs / auth.go
Created August 12, 2021 09:56
Golang basic auth example
package main
import (
"encoding/base64"
"net/http"
"strings"
)
type handler func(w http.ResponseWriter, r *http.Request)
@mortymacs
mortymacs / disable_signals.py
Created August 5, 2021 11:34 — forked from bruce-shi/disable_signals.py
Temporarily disable all signals in django.
from collections import defaultdict
from django.db.models.signals import *
class DisableSignals(object):
def __init__(self, disabled_signals=None):
self.stashed_signals = defaultdict(list)
self.disabled_signals = disabled_signals or [
pre_init, post_init,
pre_save, post_save,