Skip to content

Instantly share code, notes, and snippets.

View rakia's full-sized avatar

Rakia Ben Sassi rakia

View GitHub Profile
@rakia
rakia / zoneless-component.ts
Created May 22, 2024 19:51
Angular: zoneless component
import { bootstrapApplication } from '@angular/platform-browser';
import { provideExperimentalZonelessChangeDetection } from '@angular/core';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [
provideExperimentalZonelessChangeDetection(),
],
});
@rakia
rakia / control-flow.html
Created May 22, 2024 18:03
Angular: Control Flow example
@if (isOrganization) {
<profile-organization [data]="userData"></profile-organization>
} @else if (isPremium) {
<profile-premium [data]="userData"></profile-premium>
} @else {
<profile-basic [data]="userData"></profile-basic>
}
@rakia
rakia / memory-safe-python-program.py
Created May 3, 2024 17:17
A memory-safe Python program
# Python handles memory management for you
list_of_items = ['item1', 'item2', 'item3']
print("Current list:", list_of_items)
# When objects like lists are no longer needed, Python cleans up
del list_of_items # This frees up memory space automatically
# The garbage collector in Python manages the allocation and deallocation of memory
@rakia
rakia / remote-control.c
Created May 3, 2024 16:51
A C program with remote control vulnerability
#include <stdio.h>
#include <string.h>
void process_command(char *input) {
char buffer[30];
strcpy(buffer, input); // Potential overflow here
// ... Process command
}
int main() {
char command[100];
@rakia
rakia / data-breaches.c
Created May 3, 2024 16:43
A C program with data breaches
#include <stdio.h>
#include <string.h>
void process_data(char *input) {
char buffer[50];
strcpy(buffer, input); // Potential overflow here
// ... Process data
}
int main() {
char data[100];
@rakia
rakia / authentication-buffer-overflow.c
Created May 3, 2024 16:36
Imagine a program that authenticates users, based on their username and password, has a buffer overflow vulnerability
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool authenticate(char *username, char *password) {
char stored_password[16];
strcpy(stored_password, "secret"); // The real password
return strcmp(password, stored_password) == 0;
}
int main() {
@rakia
rakia / non-memory-sage-c-program.c
Created May 3, 2024 16:00
A Non-Memory-Safe C program
#include <stdio.h>
#include <string.h>
void greet(char *input) {
char buffer[10];
strcpy(buffer, input); // Copy input to buffer
printf("Hello, %s!\n", buffer);
}
int main() {
char name[20];
@rakia
rakia / get-weather-wsdl-example.xml
Created April 11, 2024 20:25
SOAP API: WSDL file to use a get-weather service
<?xml version="1.0"?>
<definitions name="SimpleWeatherService"
targetNamespace="http://example.com/simpleWeather.wsdl"
xmlns:tns="http://example.com/simpleWeather.wsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
@rakia
rakia / client-get-weather.py
Created April 11, 2024 13:32
Client-side logic of GetWeather ProtoBuf (gRPC) service
import grpc
import weather_pb2
import weather_pb2_grpc
def run():
with grpc.insecure_channel('localhost:50051') as channel:
stub = weather_pb2_grpc.WeatherServiceStub(channel)
response = stub.GetWeather(weather_pb2.GetWeatherRequest(city_name="New York"))
print(f"Weather: {response.temperature} degrees")
@rakia
rakia / weather-servicer.py
Created April 11, 2024 13:31
Server-side logic of GetWeather ProtoBuf (gRPC) service
from concurrent import futures
import grpc
import weather_pb2
import weather_pb2_grpc
class WeatherServicer(weather_pb2_grpc.WeatherServiceServicer):
def GetWeather(self, request, context):
# Implement the logic to retrieve the weather here. For simplicity, returning a fixed value.
return weather_pb2.GetWeatherResponse(temperature=22.5)