Skip to content

Instantly share code, notes, and snippets.

@noureddin
noureddin / mas.pl
Last active February 2, 2018 17:55
MIPS Assembler
#!/usr/bin/env perl
use strict; use warnings;
# a MIPS Assembler
# usage: ./mas.pl infile.asm > outfile.hex
# - it outputs to stdout; redirect it to a file if you need so.
# - exactly one file shall be supplied as arg.
# every line in the input file shall be either an instruction, a comment,
# an empty line (has spaces only), or a labeled instruction, which is a label
# followed by an instrucion on the same line. Lable-only lines are NOT well
# supported.
@noureddin
noureddin / tic-tac-toe.pl
Last active January 6, 2018 21:52
a simple, two-player tic-tac-toe in perl
#!/usr/share/env perl
# a simple, two-player tic-tac-toe game
use strict; use warnings;
my @cells;
my %valid_input = map { $_ => undef } (1..9);
my $who_has_turn = 1; # 1 or 2, for player 1 or 2, respectively
@noureddin
noureddin / split.h
Last active February 3, 2018 21:47
modern replacement for strtok
#include <string>
#include <vector>
// If you are using strtok, or a variant like strtok_r or strtok_s, in your
// C++ code, you may be interested in this instead.
//
// This header contains a function called `split`, that takes a string, and
// an array of delimiting characters, and breaks the string on the delimiters,
// in a way similar to strtok, and returns a vector of strings representing
// the tokens.

Automated Verilog MIPS Testing

This documents our humble attempt at automating the testing of a MIPS project in Verilog using Perl.

We had two test scripts, general_test.pl and predefined_test.pl.

general_test.pl is made so that you can easily initialize some registers and pass a set of instructions and check the values of any number of registers after the execution; it was used for evaluating and grading the project.

@noureddin
noureddin / slideshare-dl.pl
Last active April 22, 2018 06:29
Download presentations from slideshare.net
#!/usr/bin/env perl
use strict; use warnings;
# download presentations from slideshare.net
sub help {
use File::Basename 'basename';
printf 'slideshare-dl - download presentations from slideshare.net
USAGE: %s -dl url_of_slides... [-r small|normal|full] [-q|-v]
@noureddin
noureddin / magic.c
Last active July 16, 2018 18:57
using buffer overflow to loop
// prints the integers from 0 to 10
// compile with zero optimizations (use no `-O` flags, or only `-O0`)
// works on ubuntu xenial with gcc 5.4.0 (changed the buffer line from the original to work)
// src: https://old.reddit.com/r/ProgrammerHumor/comments/7p9c25/printing_all_integers_from_0_to_10/
#include <stdio.h>
int a[3][3][3][3][3] = {0};
void magic() {
@noureddin
noureddin / svd.py
Last active August 11, 2018 01:07
using svd to “compress” an image, using opencv and numpy
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# do a lossy compression to an image using Single-value Decomposition (SVD)
# using numpy and opencv (and python)
import numpy as np
import cv2
from sys import argv
@noureddin
noureddin / hyperpdfize.py
Created March 12, 2020 09:26
html2pdf converter using Blink/Chromium, using PyQt5 and PyQtWebEngine
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: set et sw=4 ts=4 :
# Pythonized from: https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-html2pdf-example.html
# Differences from the C++ example:
# - handling local HTML files relative to the current working directory is added.
# - incognito mode is used.
# - removed tr() calls from the class.
# - a few cosemetic changes.
@noureddin
noureddin / AnkiInstall
Last active November 26, 2020 06:08
A small script to install/update Anki for Desktop Gnu/Linux systems
#!/usr/bin/env perl
use v5.14; use warnings; use autodie; use utf8;
# Run as root to install or upgrade Anki. To upgrade, you have to have Anki
# installed using this script, otherwise, it will be downloaded and installed
# again. But that would not make you loss any data.
# It needs Perl 5.14, axel, tar, and make. tar and make are required.
# Perl 5.12 may be used instead. And axel can be replaced by your preferred
# downloader below.
@noureddin
noureddin / embedded-guide-ar.md
Last active July 10, 2020 22:03
الطريق إلى الأنظمة المدمجة

الطريق إلى الأنظمة المدمجة

نقلا عن منشور للدكتور المهندس وليد عيسى، صاحب دورة الإلكترونيات العملية (مذكورة في آخر المنشور).

المحتوى مطابق للمنشور الأصلى وقت نسخه (عدا السطر الأول الخاص بحذف منشورات سابقة). لم أعدّل أي حرف فيه. وإنما فحسب طوّعت تنسيقه ليناسب Markdown (لغة تنسيق مستندات مستخدمة على GitHub).