Skip to content

Instantly share code, notes, and snippets.

View pstiasny's full-sized avatar

Paweł Stiasny pstiasny

View GitHub Profile
@pstiasny
pstiasny / gist:1169534
Created August 24, 2011 23:05
Bash man shortcut
# Map Meta-m in bash to a function displaying man for the command you are entering
# Useful for looking up arguments
function split-command { man ${READLINE_LINE%% *}; }
bind -x '"\em":"split-command"'
@pstiasny
pstiasny / Map.cc
Created November 26, 2011 18:55
avl map implementation with copy-on-change (incomplete)
#include "Map.hpp"
#include <iostream>
template <class Key, class T, class Compare>
Map<Key, T, Compare>::Node::Node(const value_type& _data) : data(_data) {
left = right = NULL;
height = 1;
}
@pstiasny
pstiasny / Makefile
Created December 18, 2011 22:37
Remove all occurences of charactes from string 2 in string 1
CFLAGS = -m32
text: main.o text.o
gcc $(CFLAGS) main.o text.o -o text
main.o: text.c
gcc $(CFLAGS) -c text.c -o main.o
text.o: text.s
nasm -f elf text.s
@pstiasny
pstiasny / gist:1895284
Created February 23, 2012 21:58
demo vtk
<VTKFile type="UnstructuredGrid">
<UnstructuredGrid>
<!-- kawal danych -->
<Piece NumberOfPoints="3" NumberOfCells="1">
<!-- wartosci w punktach -->
<PointData Scalars="Coolness">
<DataArray Name="Coolness" type="Float32">
1.0
1.0
1.2
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
char* logo =
" ____ ____ ____ ____\n"
set shell=/bin/sh
" vundle
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
" paczki
Bundle 'tpope/vim-fugitive'
@pstiasny
pstiasny / gist:7936600
Created December 12, 2013 22:19
tmux.conf
$ cat ~/.tmux.conf
set-option -g prefix C-a
bind-key C-a last-window
bind-key j command-prompt -p "join pane from:" "join-pane -s '%%'"
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
set -g base-index 1
% funkcja pierwotna
f = @(x1,x2) 10*(2*x2.^2-x1).^2+(x2-2).^2;
% gradient
df = @(x) [
20*x(1) - 40*x(2)^2;
2*x(2) - 80*x(2)*(x(1) - 2*x(2)^2) - 4
]
% macierz drugich pochodnych
@pstiasny
pstiasny / sigreport.py
Last active August 29, 2015 14:02
record reaching points in code
import os
import inspect
def record_point(name=''):
pid = os.getpid()
f = inspect.currentframe()
# redis.set ...
print('{} = {}:{}:{}'.format(
pid,
f.f_back.f_code.co_filename,
@pstiasny
pstiasny / models.py
Created March 25, 2015 17:13
Circular reference with Django ORM and Postgres without breaking NOT NULL FK constraints
from django.db import connection, models
class PrefetchIDMixin(object):
def prefetch_id(self):
# <https://djangosnippets.org/snippets/2731/>
cursor = connection.cursor()
cursor.execute(
"SELECT nextval('{0}_{1}_{2}_seq'::regclass)".format(
self._meta.app_label.lower(),