Skip to content

Instantly share code, notes, and snippets.

View mofm's full-sized avatar

Emre Eryilmaz mofm

View GitHub Profile
@mofm
mofm / functions.zsh
Last active December 27, 2022 20:00
zsh function example: ssh jump
jump() {
if (( # == 0 ))
then
echo "Usage: $0 hostname [port]"
return 1
fi
CMD="-J USERNAME@HOSTNAME:PORT $1"
# add remote ssh port if default ssh port isn't used
if [[ -z "$2" ]]
then
@mofm
mofm / ip_classes.rs
Created November 2, 2022 11:57
example-1: find class of given ip address
use std::io;
use std::process::exit;
#[derive(Debug)]
enum IpClasses {
A,
B,
C,
D,
E,
@mofm
mofm / dice_game.rs
Created November 2, 2022 11:15
dice games in rust-lang. Player 1 vs Player 2. per guess is 1 puan. first 3 puan is winner!
use rand::Rng;
use std::io;
enum Players {
Player1,
Player2,
}
struct Game {
player1: u32,
@mofm
mofm / dice_roll.rs
Created November 1, 2022 23:40
6 dice types, roll and sum
use rand::Rng;
use std::io;
enum Dice {
D4,
D6,
D8,
D10,
D12,
D20,
// generate the nth fibonacci number
// Time Complexity: Exponential, as every function calls two other functions
use std::io;
fn fib(n: u32) -> u128 {
return if n == 0 {
0
} else if n == 1 {
1
@mofm
mofm / guessnumber.py
Created October 15, 2022 14:28
Guest number example for algoritms course
print(input("Guess a number(1-100) and Press enter to continue: "))
low = 0
high = 100
count = 0
while True:
count += 1
guess = (low + high) // 2
print("Is it", guess, "?")
answer = input("Enter 'h' if it's too high, 'l' if it's too low, or 'c' if it's correct: ")
@mofm
mofm / parse_urls.py
Created October 7, 2022 18:42
parse all links in a web page
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
from html.parser import HTMLParser
from urllib.parse import urlparse
import gzip
def get_domain(url):
return bool(urlparse(url).netloc)
@mofm
mofm / alpine-nspawn.sh
Created December 24, 2021 16:58
create alpine linux rootfs for systemd-nspawn
#!/bin/sh -e
MIRROR="http://dl-cdn.alpinelinux.org/alpine"
VERSION="latest-stable"
[ "$(id -u)" -ne "0" ] && echo "You need to be root" >&2 && exit 1
[ -z "$1" ] && echo "Usage: $0 destination" >&2 && exit 0
dest="$1"
apkdir="$(mktemp -d)"
@mofm
mofm / suppress_list_01.txt
Created December 14, 2021 11:00
Suricata Suppress List 01
#SURICATA STREAM ESTABLISHED packet out of window
suppress gen_id 1, sig_id 2210020
#SURICATA STREAM reassembly overlap with different data
suppress gen_id 1, sig_id 2210050
#SURICATA STREAM excessive retransmissions
suppress gen_id 1, sig_id 2210054
#SURICATA zero length padN option
@mofm
mofm / maillog-hashnize.pl
Created October 10, 2021 21:15 — forked from xtetsuji/maillog-hashnize.pl
enhancement of "pflog" for parsing maillog of postfix 2.3 or higher version.
#!/usr/bin/perl
# "pflog" enhancement for parsing maillog of postfix 2.3 or higher version.
# "pflog" see: http://www.tmtm.org/ruby/pflog/pflog-0.3
use strict;
use warnings;
use Time::Local;
use Getopt::Long;
#use Data::Dumper;