Skip to content

Instantly share code, notes, and snippets.

View markogresak's full-sized avatar

Marko Grešak markogresak

View GitHub Profile
@markogresak
markogresak / draw-triangle.dart
Created November 12, 2014 16:31
Dart code for drawing a triangle based on starting coordinates, width and inner angles
void drawLine(x1, y1, x2, y2) {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
}
double tanDeg(num x) {
return tan(x * PI/180);
}
function info {
if [[ -n "$1" ]]; then
OIFS=$IFS
IFS=':' read -a user <<< "$(getent passwd $1)"
if [[ "${user[0]}" != "$1" ]]; then
echo "$1: err"
else
printVals=()
if ((${user[2]} == ${user[3]})); then
printVals+=("enaka")
#include <sys/file.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#define E_O_I "odpiranju vhodne"
#define E_L_I "zaklepanju vhodne"
#define E_UL_I "odklepanju vhodne"

Deskriptorji

Shranimo jih lahko kot int

  • STDIN_FILENO: stdin
  • STDOUT_FILENO: stdout

Ali po imenu datoteke:

int deskriptor = open("pot/ime", {dovoljenje}) // vrne deskriptor

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

OS izziv 7

Izpis procesov

ps -Ao pid,comm,%mem,user,%cpu --sort=-pcpu --no-headers
  • -A: vsi procesi (po defaultu so samo od trenutnega uporabnika)
  • -o: filtriranje outputa, flagi so v besedilu naloge (lahko je spremenljivka)
  • --sort=-pcpu: sortiranje po porabi cpu
#!/bin/bash
function help {
echo -en "\033cPritisnite:
q - izhod iz programa (quit)
h - izpiše pomoč in čaka na pritisk tipke (help)
c - menjava vidnosti izpisa ukaza (command toggle display)
m - menjava vidnosti izpisa porabe pomnilnika (memory toggle display)
p - menjava vidnosti izpisa zasedenosti cpu (cpu toggle display)
u - menjava izpisa uporabnika (user toggle display)
@markogresak
markogresak / Agile.md
Last active August 29, 2015 14:12
Useful dev related stuff

Here is how to do something in an agile fashion:

What to do:
  • Find out where you are
  • Take a small step towards your goal
  • Adjust your understanding based on what you learned
  • Repeat
#!/bin/bash
# Napišite skripto streznik.sh, ki bo komunicirala s svetom preko
# imenovane cevi streznik.cev. Na to cev lahko drugi procesi pošiljajo
# ukaze strežniku:
# - connect ime_cevi (povezovanje, podano je ime cevi, kamor naj strežnik pošilja odgovore)
# - add N1 N2 N3 N4 ... (seštej podana števila)
# - mult N1 N2 N3 N4 ... (zmnoži podana števila)
# - disconnect (odklopi se od strežnika)