Skip to content

Instantly share code, notes, and snippets.

View hamidb80's full-sized avatar
🕸️
The spider’s house is the weakest of houses. If only they knew!

Palestine/humanity is in danger hamidb80

🕸️
The spider’s house is the weakest of houses. If only they knew!
View GitHub Profile
@hamidb80
hamidb80 / programming-as-theory-building.md
Created April 29, 2025 10:36 — forked from onlurking/programming-as-theory-building.md
Programming as Theory Building - Peter Naur

Programming as Theory Building

Peter Naur

Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct

# calculate check digit for a UPC-A barcode
Code ← [1 2 3 4 5 6 7 8 9 0 1]
Coeffs ← +1 ×2 ◿2 +1 ⇡ ⧻ Code
Check ← ⌵ -10 ◿10 /+ × Code Coeffs
Final ← ⊂ Code Check
Code
Coeffs
Check
Final
@hamidb80
hamidb80 / linux_change_dns.sh
Last active April 19, 2024 10:45
change the DNS setting of your linux system
#!/bin/sh
LOC="/etc/resolvconf/resolv.conf.d/head"
if [[ $1 = "remove" ]]; then
echo "nameserver 1.1.1.1" | sudo tee $LOC
elif [[ $1 = "begzar" ]]; then # begzar.ir
echo "nameserver 185.55.226.26" | sudo tee $LOC
echo "nameserver 185.55.225.25" | sudo tee -a $LOC
## originally writeen for brother Omar. thanks to:
## https://github.com/nramos0/binhex4-rs/
## https://gist.github.com/i-e-b/fe0a0158ae61973802a9
import std/[strutils, sequtils, os]
type
DecodedHqxContent = distinct string
@hamidb80
hamidb80 / openMP-parallel-for-shared-local.c
Last active November 2, 2023 07:30
openMP parallel for loop with shared & local variables
#include <stdio.h>
#include <omp.h>
int main(){
int partial_Sum, total_Sum;
#pragma omp parallel private(partial_Sum) shared(total_Sum)
{
partial_Sum = 0;
total_Sum = 0;
@hamidb80
hamidb80 / python_def_to_nim_proc.nim
Created June 16, 2023 07:00
converts python's way of defining function to Nim way.
import std/macros
import macroplus
# ----- impl
template emp: untyped = newEmptyNode()
func resolveParams(rawParams: openArray[NimNode]): seq[NimNode] =
template init =
result.add newNimNode nnkIdentDefs
import std/strutils
type BookFeatures = enum
bfIntroAndDownload = "معرفی و دانلود"
bfIntroAndPurchase = "معرفی، خرید و دانلود"
bfFreeContent = "رایگان"
bfBook = "کتاب"
bfAudioBook = "کتاب صوتی"
bfPodcast = "پادکست"
@hamidb80
hamidb80 / customize_font.nim
Last active January 29, 2023 06:20
customizing subtitle font [for `.SRT`] - made for Arabic/Persian subtitles in `Kdenlive` software which uses html-4 for font settings
import std/[strformat, strutils]
import sbttl
# ------------------------
type
Lang = enum
fa, en
Dir = enum
@hamidb80
hamidb80 / main.nim
Created December 30, 2021 21:17
telebot send contact info reply to message causes error
import telebot, asyncdispatch, logging, options
var L = newConsoleLogger(fmtStr = "$levelname, [$time] ")
addHandler(L)
func singleReply*(btn: KeyboardButton): ReplyKeyboardMarkup =
ReplyKeyboardMarkup(`type`: kReplyKeyboardMarkup, keyboard: @[@[btn]])
const API_KEY = "..."