Skip to content

Instantly share code, notes, and snippets.

Avatar
🤙
Looking for a project to help with/contribute!

Patryk Małek pmalek

🤙
Looking for a project to help with/contribute!
View GitHub Profile
@pmalek
pmalek / shared_tmux.sh
Created Feb 9, 2018
Tmux read only shared session setup
View shared_tmux.sh
#/bin/bash
SHARED_SESSION_FILE=/tmp/shared_tmux_session
set -e
tmux -2 -S ${SHARED_SESSION_FILE} new -s guest -d
sudo chown $(whoami) ${SHARED_SESSION_FILE}
sudo chmod 777 ${SHARED_SESSION_FILE}
@pmalek
pmalek / install_gcc.sh
Last active Jan 15, 2019
gcc installation script for Centos6.6 (probably can be used for other distributions). It also installs dependencies like mpc, mpfr and gmp !NOTE: As of now this only works for installations with PREFIX=/usr/local
View install_gcc.sh
#!/bin/bash
LOGFILE=/tmp/gcc_install.log
# $1 - package name
errorIf(){
if [ $? -ne 0 ]; then
echo "Something was wrong with $1"
exit 1
fi
@pmalek
pmalek / count_pages.sh
Created Jan 20, 2014
Bash script to count pages of pdfs in current directory
View count_pages.sh
#!/bin/bash
sum_pages=0
for file in *.pdf ; do
cur_pages=$(pdfinfo $file | awk '/Pages/{print $2}')
echo "pdf: $file has $cur_pages pages."
sum_pages=$(( sum_pages + cur_pages))
done
echo "All pdf files in this directory have $sum_pages pages."
@pmalek
pmalek / new_gist_file
Created Sep 26, 2016
tcpdump from a remote machine to fifo on local machine and read via wireshark
View new_gist_file
mkfifo fifo
TCPHOST="10.0.0.1"; while true ; do \
ssh $TCPHOST 'tcpdump -s 0 -U -n -w - "!igmp && !arp && !rarp && !(host 224.0.0.1) && !(port 22) && !(port 67) && !(port 53) && !(port 123) && !(port 5353) && !(port 137)"' > fifo; \
done
# on another console
wireshark -k -i fifo
View main.go
package main
import (
"crypto/rand"
"crypto/rsa"
"encoding/json"
"fmt"
"log"
jose "gopkg.in/square/go-jose.v2"
)
func main() {
@pmalek
pmalek / parse.go
Last active Oct 6, 2017
really quick and dirty stackoverflow jobs feed parsing with Go
View parse.go
package main
import (
"encoding/xml"
"fmt"
"io"
"os"
"regexp"
"strings"
"time"
@pmalek
pmalek / profile_vim
Last active Aug 17, 2017
vim profiling (e.g. for finding slow plugins)
View profile_vim
http://stackoverflow.com/a/12216578/675100
:profile start profile.log
:profile func *
:profile file *
" At this point do slow actions
:profile pause
:noautocmd qall!
// --------------------
@pmalek
pmalek / fib.py
Created Jul 15, 2016
python fibonacci
View fib.py
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 Jul 15, 2016
fibonacci tail recursion
View fib.cpp
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 Jun 13, 2016
compare version c string like "1.2.10"
View main.c
#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;