Skip to content

Instantly share code, notes, and snippets.

@shakram02
shakram02 / SumAll.cpp
Last active May 7, 2016 18:45
Sums all the input arguments
#include <iostream>
#include<stdlib.h>
template <typename T>
int Sum(T t)
{
return t;
}
template<typename T, typename... Args>
@shakram02
shakram02 / TiledMatrixMultiplyAMP.cpp
Created May 8, 2016 06:33
AMP - Tiled matrix multiplication
void MatrixMultiplyTiled(vector<int>& vC, const vector<int>& vA,
const vector<int>& vB, int M, int N, int W)
{
// first mat: M × W
// second mat: W × N
// Note that the const before the float when creating a and b,
// will result in the underling data only being copied to the accelerator
// and not be copied back – a nice optimization.
@shakram02
shakram02 / quran_downloader.py
Last active April 23, 2018 15:33
Downloads quraan for a specified reciter from althkr.com (the script isn't by any means optimized, but it just works)
import urllib.request
import sys
counter = 0
def main(start, end):
"""
To get the list of reciters, visit this link http://althkr.com/Reciters.php
Note that the folder will be downloaded in the current directory. Make sure you have space
and that you can handle the clutter. I suggest running the script in an empty folder
@shakram02
shakram02 / update_then_shutdown.sh
Last active December 31, 2018 19:31
Update pacman then shutdown
# Updates the system, answering all the prompts with "yes" then shuts the PC down after 20 mins of completion
# only IF the update process completes successfully
# Helpful if you want to start an update and go to bed zzzzzZzZzZZ
yes | pacman -Syu && shutdown 20
@shakram02
shakram02 / memory_care.c
Created April 25, 2019 19:14
This code illustrates proper use of string functions and how to allocate memory for them along with some tips
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h> // for tolower
// Set buffer sizes
#define MAX_SIZE 256
#define SMALL_BUFF_SIZE 8
void replace_newline_with_null(char *s)
{
@shakram02
shakram02 / make_transparent_watermark.py
Created April 28, 2019 13:32
Draw black text on a transparent image using PIL
# Source: https://webkul.com/blog/python-imaging-librarypil-examples/
from PIL import Image
from PIL import Image
from PIL import ImageEnhance
from PIL import ImageDraw, ImageFont
img = Image.open("original.jpg")
margin_left,margin_top = img.size
width, height = img.size
image_mode = img.mode
@shakram02
shakram02 / ArabicNormalizer.kt
Last active July 25, 2019 08:19
Replaces Alef, Waw, Yeh variants with their original letters [plain Alef, plain Waw, plain Yeh] and removes tashkeel and ligatures
/**
* Author: @shakram02
* Replaces Alef, Waw, Yeh variants with their original letters [plain Alef, plain Waw, plain Yeh].
* Removes Arabic-related symbols and ligatures
*/
object ArabicNormalizer {
private val ALEF = "\u0627"
private val WAW = "\u0648"
private val YEH = "\u064A"
private val normalizationCache: HashMap<String, String> = hashMapOf()
@shakram02
shakram02 / FFMPEG_Writer.py
Created July 28, 2019 13:16
A dropin replacement for OpenCv::VideoWriter in python.
"""
The MIT License (MIT)
[OSI Approved License]
The MIT License (MIT)
Copyright (c) 2015 Zulko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@shakram02
shakram02 / get_macs.rs
Created September 7, 2019 04:56
get MAC addresses of all interfaces on a Linux-ish system, returns a hashmap of (iface_name, mac_addr) without any external dependencies
use std::collections::HashMap;
use std::fs;
use std::io::Read;
use std::path::Path;
fn get_macs() -> HashMap<String, String> {
// cat the /sys/class/net/iface/address to get the MAC
// based on: https://stackoverflow.com/questions/26346575/how-to-get-mac-address-in-rust
let net = Path::new("/sys/class/net");
let entry = fs::read_dir(net).expect("Error");
@shakram02
shakram02 / build_ffmpeg.sh
Created September 15, 2019 15:19
Sciprt used to build FFMPEG from sources and includes libraries that I need
#!/bin/bash
./configure --enable-libopenh264 --enable-libx264 --enable-libwavpack --enable-libvorbis --enable-libopus --enable-libmp3lame --enable-libass --enable-libdav1d --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libopenjpeg --enable-gpl --enable-nonfree
6243 ./configure --enable-libopenh264 --enable-libx264 --enable-libwavpack --enable-libvorbis --enable-libopus --enable-libmp3lame --enable-libass --enable-libdav1d --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libopenjpeg --enable-libsoxr --enable-gpl --enable-nonfree