Skip to content

Instantly share code, notes, and snippets.

View mralfarrakhan's full-sized avatar

Rafky Alfarrakhan mralfarrakhan

View GitHub Profile
@mralfarrakhan
mralfarrakhan / edomautofill.js
Last active December 31, 2023 07:45
EDOM auto-fill
(() => {
let radios = document.querySelectorAll('input[type=radio]');
for(let i = 0; i < radios.length; i++){
if(radios[i].getAttribute('value') == `${Math.floor(Math.random() * 2) + 4}`){ //randomly generate value 4-6
radios[i].checked = true;
}
}
})()
@mralfarrakhan
mralfarrakhan / convolve.cpp
Created March 6, 2022 15:08
Basic 1D convolution function
#include <vector>
template<typename T>
auto convolve(std::vector<T> v1, std::vector<T> v2){
std::vector<T> res(v1.size() + v2.size() - 1);
for(int i = 0; i < v1.size(); i++){
int j = i;
for(const auto &ev2 : v2){
res[j++] += v1[i]*ev2;
#include <fmt/core.h>
#include <vector>
using stream_t = std::vector<double>;
using split_t = std::vector<stream_t>;
auto deinterleave(stream_t framesstream, int nchannel){
auto nframe = framesstream.size();
split_t res(nchannel);
@mralfarrakhan
mralfarrakhan / intparse.go
Created May 11, 2022 04:03
integer to list of integer
func iparse( n int) []int {
var res []int
var dec int
var par int
pwr := 1
for i := 0; dec <= n; i++ {
dec = pow(10, pwr) //pow(int, int) int func.
par = 10*(n % dec)/dec
@mralfarrakhan
mralfarrakhan / opfinder.user.js
Created June 1, 2022 09:24
get post's op user id
// ==UserScript==
// @name 9Gag OP Finder
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description 9gag op finder
// @author deadManAlive
// @match https://9gag.com/gag/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=9gag.com
// @grant none
// ==/UserScript==
@mralfarrakhan
mralfarrakhan / bitstring.cpp
Last active June 29, 2022 05:26
julia inspired bitstring function
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
using str = std::string;
static str itob(const unsigned int& num) {
str res = "";
@mralfarrakhan
mralfarrakhan / ftemphell.cpp
Created December 5, 2022 17:03
some experiment with functional and template to note
#include <iostream>
#include <vector>
#include <functional>
#include <ranges>
#include <string>
template <template<class> class I, class T>
requires std::ranges::output_range<I<T>, T> && std::convertible_to<T, double>
void foriter(I<T>& iterable, const std::function<void(T&)>& func)
{
@mralfarrakhan
mralfarrakhan / double.ml
Created June 6, 2023 15:58
doubling rotate or something
(* input *)
let q = ['A'; 'B'; 'C'; 'D'; 'E'];;
let pos = 20;;
let rec list_print queue =
match queue with
| [] -> ()
| h :: t ->
Printf.printf "%c " h;
list_print t;;
@mralfarrakhan
mralfarrakhan / b2hfunc.ts
Last active June 27, 2023 14:15
binary to decimal
const b2h: (string) => string = (bin: string) => bin.split("")
.reverse()
.reduce((p, c, i, a) => {
switch(i % 4 === 0) {
case true:
return p.concat(a.slice(i, i + 4).join(""));
default:
return p;
}
}, <string[]>[])
@mralfarrakhan
mralfarrakhan / ocaml-on-msys2.md
Last active March 2, 2025 14:53
Installing Ocaml (latest w/o opam) in Windows via MSYS2

Installing OCaml (latest w/o opam) in Windows via MSYS2

  1. Preparation: MSYS2 MinGW64, make sure git, make, diffutils, and gcc installed, e.g. with pacman -S git make diffutils mingw-w64-x86_64-gcc.
  2. git clone https://github.com/ocaml/ocaml.git.
  3. git submodule update --init.
  4. ./configure, then make, and then install with make install.

At this point ocaml, ocamlc, and ocamlopt is already installed on the MSYS2 MinGW64 environment, but you'll hit by error like "Unbound module Stdlib".

  1. Check standard_library location via ocamlc -config, should be /mingw64/lib/ocaml.