Skip to content

Instantly share code, notes, and snippets.

View bchaber's full-sized avatar
😶
Don't shake the table

Bartek Chaber bchaber

😶
Don't shake the table
  • Warsaw University of Technology
  • Poland
View GitHub Profile
@bchaber
bchaber / main.c
Created November 19, 2024 11:04
Program do zarządzania studentami
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct student {
int uid; // unique identifier
float gpa; // grade point average
char *firstname;
char *lastname;
} student_t;
import os
import random
import string
ALPHABET = string.ascii_lowercase + string.digits
def encrypt(password, text):
message = "".join([c.lower() if c.isalnum() else "" for c in text])
plaintext = [ALPHABET.find(c.lower()) for c in message]
keystream = [ALPHABET.find(c.lower()) for c in password]
n = len(plaintext)
@bchaber
bchaber / symmetric-problem-fdm.jl
Last active May 31, 2023 08:26
Generatory problemów symetrycznych
function fdmproblem(n)
m = n
A = zeros(n*m, n*m)
dof = reshape(1:n*m, n, m)
for i=2:n, j=1:m
A[dof[i,j], dof[i-1,j]] -= 1.0
A[dof[i,j], dof[i,j]] += 1.0
end
for i=1:n, j=2:m
A[dof[i,j], dof[i,j-1]] -= 1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/sh
OUTPUT_DIR="/"
MAX_PID=65535
CGROUP_NAME="xyx"
CGROUP_MOUNT="/tmp/cgrp"
PAYLOAD_NAME="${CGROUP_NAME}_payload.sh"
PAYLOAD_PATH="${OUTPUT_DIR}/${PAYLOAD_NAME}"
OUTPUT_NAME="${CGROUP_NAME}_payload.out"
OUTPUT_PATH="${OUTPUT_DIR}/${OUTPUT_NAME}"
@bchaber
bchaber / unstable-fdtd.jl
Last active September 26, 2022 10:58
An example code for axisymmetric FDTD
ε_0 = 8.85418781e-12 # vacuum permittivity [F/m]
μ_0 = 1.256637062e-6 # vacuum permeability [H/m]
c = 299_792_458. # speed of light [m/s]
NR = 101 # number of grid points along radial direction [1]
NZ = 101 # number of grid points along axial direction [1]
RADIUS = 0.010 # radius along r-axis [m]
LENGTH = 0.010 # lenght along z-axis [m]
DZ = LENGTH / (NZ-1) # cell-size along axial direction [m]
DR = RADIUS / (NR-1) # cell-size along radial direction [m]
@bchaber
bchaber / mwe-0.jl
Last active June 21, 2022 20:41
Why const global is better than immutable struct field?
const H = 20
const W = 20
const f = zeros(9, H, W)
const rho = ones(H, W)
struct Lattice
f :: Array{Float64, 3}
end
const lattice = Lattice(f)
@bchaber
bchaber / FEM.jl
Last active April 6, 2022 08:30
Files for project
include("wave-equation.jl")
function quadmesh(a, b, Nx, Ny)
NUM_EDGES = 2(Nx*Ny) + Nx + Ny
NUM_ELEMS = Nx * Ny
el2edd = repeat([+1 +1 -1 -1], NUM_ELEMS)
el2ed = zeros(Int64, NUM_ELEMS, 4)
for jj = 1:Ny
for ii = 1:Nx
@bchaber
bchaber / com.example.KeyRemapping.plist
Last active August 21, 2023 11:22
Configure hidutil to remap Right Fn to act as Right Alt
<!--
Put this file in ~/Library/LaunchAgents/com.example.KeyRemapping.plist to
automatically remap your keys when macOS starts.
See https://developer.apple.com/library/archive/technotes/tn2450/_index.html for
the key "usage IDs". Take the usage ID and add 0x700000000 to it before putting it
into a source or destination (HIDKeyboardModifierMappingSrc and
HIDKeyboardModifierMappingDst respectively).
-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@bchaber
bchaber / dao.py
Created November 4, 2021 09:32
Data-Access-Object for working with Redis database
from json import dumps, loads
class Price:
def __init__(self, db):
self.db = db
def __getitem__(self, item):
price = self.db.hget("price", item)
if price:
return int(price)