Skip to content

Instantly share code, notes, and snippets.

View mpapierski's full-sized avatar

Michał Papierski mpapierski

View GitHub Profile
#include <iostream>
#include "json.hpp"
#include "autoprop.hpp"
using namespace mpapierski;
using json = nlohmann::json;
class Person : public AutoProp<Person> {
public:
AUTOPROP_BEGIN(Person);
@contextmanager
def convert_to_pdf(filename):
"""Creates a PDF document based on input filename.
Returns a path to PDF file
"""
client = docker.from_env()
source = os.path.join('/tmp/{}'.format(os.path.basename(filename)))
#!/usr/bin/env python3
from collections.abc import Iterable
data = [1,2,[3,4,[5,6,[7,8,[9,10,[[[11],12],[13,14,15]]]]]]]
def flatten(data):
for value in data:
if isinstance(value, (Iterable,)):
# Call recursively to yield nested values from
yield from flatten(value)
class TestView(LoginRequiredMixin, UserPassesTestMixin, View):
model = Foo
def make_dataset(self):
"""This method returns an instance of tablib.Dataset."""
pass
def get(self, request, **kwargs):
# Create empty dataset
dataset = self.make_dataset()
@mpapierski
mpapierski / models.py
Last active January 7, 2019 09:25
Custom delete in Django
class FooManager(models.Manager):
"""A manager for foos with custom filter.
Adds a clause to default query to ignore removed entries.
"""
def get_queryset(self):
"""Filter out all removed entries by default."""
return super().get_queryset().filter(removed_at__isnull=True)
@mpapierski
mpapierski / fake_babel.py
Created December 20, 2018 16:31
fake babeld
#!/usr/bin/env python
import socket
import threading
TCP_IP = '::1'
TCP_PORT = 6872
BUFFER_SIZE = 20
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
@mpapierski
mpapierski / NotesToEvernote.applescript
Created December 15, 2018 09:42
Convert iCloud Notes to Evernote using Apple Script
tell application "Notes"
set theMessages to every note
repeat with thisMessage in theMessages
set myTitle to the name of thisMessage
set myText to the body of thisMessage
@mpapierski
mpapierski / Dockerfile
Last active October 14, 2018 16:33
concraft-pl
FROM haskell:8
RUN mkdir -p /src
RUN cd /src && git clone https://github.com/kawu/concraft-pl
WORKDIR /src/concraft-pl
RUN stack setup
RUN stack install
ENTRYPOINT ["/root/.local/bin/concraft-pl"]
@mpapierski
mpapierski / replacements.sed
Created March 24, 2018 11:32
MFC to wxWidgets
s/ON_BN_CLICKED/EVT_BUTTON/g
s/AfxGetApp()/::wxGetApp()/g
s/CObject/wxObject/g
s/CRect/wxRect/g
s/CSize/wxSize/g
s/CDC/wxDC/g
s/CPoint/wxPoint/g
s/CFont/wxFont/g
s/CPen/wxPen/g
script = '''#!/bin/sh
tail -c{} $0|gunzip
exit
'''
with open('pwning2017.sh', 'wb') as fout:
with open('payload', 'rb') as fin:
payload = fin.read()
fout.write(script.format(len(payload)))
fout.write(payload)