Skip to content

Instantly share code, notes, and snippets.

View pmalek's full-sized avatar
👋
Go and Open Source enthusiast

Patryk Małek pmalek

👋
Go and Open Source enthusiast
View GitHub Profile
@pmalek
pmalek / fib.py
Created July 15, 2016 19:35
python fibonacci
def fib_to(n):
fibs = [0, 1]
for i in range(2, n+1):
fibs.append(fibs[-1] + fibs[-2])
return fibs
@pmalek
pmalek / fib.cpp
Created July 15, 2016 19:34
fibonacci tail recursion
int fib(int term, int val = 1, int prev = 0)
{
if(term == 0) return prev;
if(term == 1) return val;
return fib(term - 1, val+prev, val);
}
@pmalek
pmalek / main.c
Last active June 13, 2016 13:04
compare version c string like "1.2.10"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
/*
* Function used to compare version c strings like: "1.2.3" or "12.9.1314214"
*/
int compare_versions(char* first, char* second)
{
size_t first_last_dot1 = 0;
@pmalek
pmalek / list.c
Last active May 6, 2016 13:30
single linked list in C
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
typedef struct node
{
int val;
struct node* next;
} node;
@pmalek
pmalek / main.sh
Created March 8, 2016 12:10
How to launch wireshark getting data from tcpdump on another machine
mkfifo fifo
wireshark -k -i fifo &
while true; do ssh MACHINE_IP 'tcpdump -s 0 -U -n -w - "! arp && host 10.0.0.1"' > fifo; done
@pmalek
pmalek / show_LBAs_written.sh
Created January 24, 2014 13:16
Show LBAs, MBs and GBs written to disk
#!/bin/bash
scale=3
lbas=$(sudo smartctl --all /dev/sda | grep Total_LBAs_Written | awk '{print $(NF)}')
mbs=$(( $lbas / 2048 ))
# gbs=$(( $mbs / 1024.0 ))
gbs=$(bc -l <<< "scale=3 ; $mbs / 1024.0")
echo "LBAs written: $lbas"
@pmalek
pmalek / commit-msg.py
Created November 14, 2015 13:04
commit-msg hook checking whether there already exists a commit in git repository with passed in commit message
#!/usr/bin/python
from subprocess import check_output
import sys
class Colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
@pmalek
pmalek / main.c
Created June 12, 2015 10:35
Search for palindroms from one file and put it alphabetically in another
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
int is_pal(char* word) {
size_t len = strlen(word);
char* begin = word;
char* end = word + len - 2; // -2 beacuse we get the newline char as well
if (len == 1) {
@pmalek
pmalek / results_pypy2.5.1
Created June 1, 2015 19:53
python vs pypy comparison benchmarks using Python 2.7.6 and PyPy 2.5.1
Python 2.7.9 (2.5.1+dfsg-1~ppa1+ubuntu14.04, Mar 27 2015, 19:19:42)
[PyPy 2.5.1 with GCC 4.8.2]
Using arena file:
example_benchmarks/zeros.py
- zeros_imul
- zeros_mul
- zeros_repeat
- zeros_slow
Using benchmark file:
@pmalek
pmalek / README
Last active August 29, 2015 14:13
ralink mt7601 linux driver patch. Take a look into README
This patch may not necessarily work - this is a better version at launchpad by Victor Martinez https://code.launchpad.net/~victored/+junk/mt7601U-linux-driver-64bit
after:
sudo make install,
do
sudo modprobe mt7601Usta