Skip to content

Instantly share code, notes, and snippets.

View ramajd's full-sized avatar
🎯
Focusing

Reza Alizadeh Majd ramajd

🎯
Focusing
View GitHub Profile
@ramajd
ramajd / proc.cmake
Created June 24, 2024 10:42
Oracle Pro*C macro for CMake
macro(compile_proc)
set(options)
set(oneValueArgs ARG)
set(multiValueArgs FILES)
cmake_parse_arguments(ARGUMENT "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
foreach(procfile ${ARGUMENT_FILES})
add_custom_command(
OUTPUT ${procfile}.cpp
COMMAND
@ramajd
ramajd / worker.js
Created February 28, 2023 06:52
CF worker
export default {
async fetch(req) {
try {
const url = new URL(req.url);
const splitted = url.pathname.replace(/^\/*/, '').split('/');
const address = splitted[0];
url.pathname = splitted.slice(1).join('/');
url.hostname = address;
url.protocol = 'https';
return fetch(new Request(url, req));
@ramajd
ramajd / chain-of-responsibility.rs
Created January 17, 2023 20:52
Sample code to implement Chain of responsibility in Rust
trait IProcessor<'a> {
fn set_next(&'a mut self, next: &'a mut dyn IProcessor<'a>);
}
struct Processor<'a> {
next: Option<&'a mut dyn IProcessor<'a>>,
}
impl<'a> IProcessor<'a> for Processor<'a> {
fn set_next(&'a mut self, next: &'a mut dyn IProcessor<'a>) {
@ramajd
ramajd / tag-styler.html
Created April 3, 2022 05:55
tag-styler.html
<html>
<body>
<div>
<a href="example.com/123123213/123123">first example</a>
<a href="another link">2nd example</a>
<a href="this-is-the-2nd-example.com">third example</a>
<a href="example/asdasd/bbb">another example</a>
</div>
</body>
@ramajd
ramajd / constant_array.c
Created March 16, 2022 11:54
array get/set in constant time
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
struct array {
int* data;
int* set_list;
int* set_pos_list;
int set_count;
int length;
@ramajd
ramajd / macro3.c
Created January 18, 2020 20:45
macro concatnation example
#include <stdio.h>
struct command {
char *name;
void (*function)(void);
};
#define MKCMD(cmd) { #cmd, cmd ## _command }
@ramajd
ramajd / macro2.c
Created January 18, 2020 20:28
macro argument string representation
#include <stdio.h>
#define WARN_IF(EXPR) \
if (EXPR) { \
fprintf(stderr, "Warning: " #EXPR "\n"); \
}
int main() {
int x = 1;
WARN_IF(x == 1);
@ramajd
ramajd / macro.c
Created January 18, 2020 19:43
preprocessor definition in c
#include <stdio.h>
#ifndef MYFLAG
#define MYFLAG "default flag"
#endif
int main() {
printf("compiled with: %s\n", MYFLAG);
return 0;
}
@ramajd
ramajd / hello.c
Created December 4, 2019 09:33
hello.c
// hello.c
#include <stdio.h>
int faulty_devider(int first, int second) {
return first / second;
}
int main() {
int a = 100;

Keybase proof

I hereby claim:

  • I am ramajd on github.
  • I am r_majd (https://keybase.io/r_majd) on keybase.
  • I have a public key ASD8FvU2AO_Kt4Uf8iJcr7lVLLxIecd4LnfecId95U3p8wo

To claim this, I am signing this object: