Skip to content

Instantly share code, notes, and snippets.

View pstiasny's full-sized avatar

Paweł Stiasny pstiasny

View GitHub Profile
@pstiasny
pstiasny / CMakeLists.txt
Created March 19, 2024 19:01
dump declarations using clang Tooling API
cmake_minimum_required(VERSION 3.10)
# Set your project name and version
project(MyClangProject VERSION 1.0)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# add_link_options("-fuse-ld=lld")
set(NO_RTTI "-fno-rtti")
@pstiasny
pstiasny / pure-io.py
Created January 22, 2018 04:35
IO monad recreated in Python
class IO(object):
@classmethod
def ret(cls, x):
return IOReturn(x)
def bind(self, f):
return IOBind(self, f)
class IOBind(IO):
{-# LANGUAGE UnicodeSyntax #-}
type ℝ = Float
data ℝ³ = ℝ³ !ℝ !ℝ !ℝ deriving (Show)
(⋅) ∷ ℝ³ → ℝ³ → ℝ
(ℝ³ x1 x2 x3) ⋅ (ℝ³ y1 y2 y3) = x1 * y1 + x2 * y2 + x3 * y3
main =
let x = ℝ³ 2 0 1
@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(),
@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,
% 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 / 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
set shell=/bin/sh
" vundle
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
" paczki
Bundle 'tpope/vim-fugitive'
#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"
@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