Skip to content

Instantly share code, notes, and snippets.

View yetimdasturchi's full-sized avatar
👨‍💻
Fisting code

Manuchehr Usmonov yetimdasturchi

👨‍💻
Fisting code
View GitHub Profile
@yetimdasturchi
yetimdasturchi / serv.md
Last active March 29, 2025 23:30
Single line web server: bash aliases to quickly spin up a Python HTTP server.

Single line web server

Bash aliases to quickly spin up a Python HTTP server:

  • Starts at a default or custom port
  • Automatically finds the next available port if taken
  • Optionally opens the server in your default web browser

Installation

@yetimdasturchi
yetimdasturchi / mailq_cleaner.sh
Created January 28, 2025 16:11
Mail queue cleaner script for antispam.
#!/bin/bash
CURRENT_TIME=$(date +%s)
mailq | awk '/^[A-F0-9]/ {print $1, $3, $4, $5}' | while read -r ID MONTH DAY TIME; do
MESSAGE_DATE="$MONTH $DAY $TIME $(date +%Y)"
MSG_TIMESTAMP=$(date -d "$MESSAGE_DATE" +%s 2>/dev/null)
if [ $? -ne 0 ]; then
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <stdint.h>
#include <pthread.h>
void restart_program() {
char program_path[100];
<?php
//Tasofidiy son generatsiya qilish
function lcg(&$seed) {
//ushbu qiymatlar CSda tasodifiy son generatsiyasi uchun eng ko'p statistikalarga asoslanib aniqlangan
$a = 1664525;
$c = 1013904223;
// 2ning 32-darajasi
$m = pow(2, 32);
@yetimdasturchi
yetimdasturchi / vanilla_hater.c
Created April 2, 2024 23:27
Example code for explaining how malloc and free work in C language.
#include <sys/mman.h>
void* c_malloc(size_t size) {
void* ptr;
asm volatile (
"mov $9, %%rax\n"
"mov $0, %%rdi\n"
"mov %1, %%rsi\n"
"mov $3, %%rdx\n"
@yetimdasturchi
yetimdasturchi / smilar.c
Created March 25, 2024 05:20
Programming Classics: Implementing the World's Best Algorithms by Oliver. Smilar text implementation.
#include <stdio.h>
#include <string.h>
void similar_str( const char* txt1, int len1, const char* txt2, int len2, int* pos1, int* pos2, int* max, int* count ) {
*max = 0;
*count = 0;
for ( int i = 0; i < len1; i++ ) {
for ( int j = 0; j < len2; j++ ) {
int l = 0;
@yetimdasturchi
yetimdasturchi / huffman.php
Created March 3, 2024 02:53
Huffman coding in php
<?php
function huffmannEncode($string) {
$originalString = $string;
$occurences = array();
while (isset($string[0])) {
$occurences[] = array(substr_count($string, $string[0]), $string[0]);
$string = str_replace($string[0], '', $string);
}
@yetimdasturchi
yetimdasturchi / find.php
Created February 13, 2024 05:31
Find key from array with levenshtein distance
<?php
function findArrayWithLevenshtein( $input, $dic ) {
$minDistance = PHP_INT_MAX;
$correctedWord = $input;
foreach ( $dic as $key => $value ) {
$distance = levenshtein( $input, $key );
if ( $distance < $minDistance ) {
$minDistance = $distance;
@yetimdasturchi
yetimdasturchi / copy.sh
Created January 22, 2024 06:54
Ssh kalitlarni serverlar massiviga ko'chirish
#!/bin/bash
username="root" #ssh uchun foydalanuvchi
ssh_key_path="/home/$USER/.ssh/id_rsa.pub" #ssh kalit
# serverlar ro'yxati
servers=(
server1.domain.uz
server2.domain.uz
server3.domain.uz
@yetimdasturchi
yetimdasturchi / check.php
Created July 27, 2023 15:47
Check ip address is in tasix
<?php
function check_tasix( $ip ){
$range = @file_get_contents('tasix.json');
$range = json_decode($range, TRUE);
if( !is_array( $range ) ) return false;
ksort( $range );
$ip2long = ip2long( $ip );
if( $ip2long !== false ) {