Skip to content

Instantly share code, notes, and snippets.

View smarteist's full-sized avatar
🙂
I may be slow to respond.

Ali Hosseini smarteist

🙂
I may be slow to respond.
View GitHub Profile
@smarteist
smarteist / Net.md
Last active November 17, 2024 09:45
Net basics

N2N H2H A2A!

Data transformation in networking involves different layers of addressing and encapsulation, from MAC addresses for local communication, to IP addresses for routing across networks, and IP addresses plus port numbers for application-level communication.

Each state provides a specific level of abstraction and functionality to ensure data reaches its intended destination. Each packet contains three important pieces of information, including the source and destination MAC addresses, the source and destination IP addresses, and the source and destination Port numbers.

Node to Node (MAC)

The MAC address is a unique identifier assigned to each network interface card (NIC) in a device. When a packet is transmitted on a network, it is sent to the destination MAC address, which is determined using the ARP protocol. The MAC address is used to identify the specific device on the network that the packet is intended for.

@smarteist
smarteist / sbrk.c
Last active April 22, 2023 15:52
allocate two pages, in C
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
// same as calling sbrk(0)
void *get_brk (void)
{
return (void *) syscall (SYS_brk, 0);
}
@smarteist
smarteist / conditional_variable.c
Last active May 12, 2023 14:28
conditional variable api using semaphores!
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
typedef struct {
sem_t wait_sem;
sem_t signal_sem;
int value;
} cond_var_t;
@smarteist
smarteist / ln.py
Last active June 17, 2023 15:15
CORDIC Algorithm to calc natural logarithm in python
import math
def cordic_ln(x):
if x <= 0:
raise ValueError("Input must be greater than 0")
lut = [
2.718281828459045,
1.6487212707001282,
1.2840254166877414,
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status
# Configuration Variables
CPU_CORES="2"
RAM_SIZE="2G"
DISK_SIZE="30G"
USERNAME="vm"
PASSWORD="111111"
@smarteist
smarteist / symfony.conf
Created August 1, 2023 16:56
nginx confings for symfony2
# -------------------
# SYMFONY CONF
# -------------------
server {
listen 443 ssl http2;
listen 80;
server_name domain.com www.domain.com;
charset utf-8;
root "/var/www/domain/public_html";
gzip off;

In Linux, groups are a collection of users. They are used as a means to manage and control access to resources such as files and directories. By assigning appropriate permissions to groups rather than individual users, system administrators can more efficiently manage access rights.

find /path/to/base/dir -type d | xargs chmod 755
find /path/to/base/dir -type f | xargs chmod 644

or changing files with specific extention:

find /path/to/base/dir -iname "*.php" | xargs chmod 644
@smarteist
smarteist / sshproxy.sh
Last active October 17, 2024 19:31
This script runs ssh proxy in local socks5 port 1080
#!/bin/bash -i
user="root"
pass="@PASS@@@@"
ip_address="111.111.11.11"
ssh_port=22
sudo_pass_file="/tmp/sshpass"
proxy_port=1080
@smarteist
smarteist / downloader.sh
Last active September 6, 2024 15:53
bash downloader via curl
#!/bin/bash
# Define the list of URLs
urls=(
"https://example.com/file1.mkv"
"https://example.com/file2.mp3"
)
# Resumable downloader function
download_file() {
sudo rm /usr/lib/python3.*/EXTERNALLY-MANAGED