Skip to content

Instantly share code, notes, and snippets.

Avatar
🌚
Rien

Miroslav Franc mirekfranc

🌚
Rien
  • Prague, Czech Republic
View GitHub Profile
@mirekfranc
mirekfranc / reducing_collection_of_predicates.py
Last active Aug 29, 2015
Reducing collection of predicates to a single predicate
View reducing_collection_of_predicates.py
def all_p (ps):
def __predicate (*args, **kwargs):
return all (p(*args, **kwargs) for p in ps)
return __predicate
def any_p (ps):
def __predicate (*args, **kwargs):
return any (p(*args, **kwargs) for p in ps)
return __predicate
@mirekfranc
mirekfranc / meta.hpp
Created Apr 24, 2015
experiments with template metaprogramming based on one cppcon talk
View meta.hpp
#ifndef META_H
#define META_H
namespace mirek
{
#include <climits>
// abs ////////////////////////////////////////////////////////////////////////////////
template<int N>
@mirekfranc
mirekfranc / reconstruct_etc_passwd.c
Created Apr 24, 2015
Reconstructing /etc/passwd based on API, in case of NIS or LDAP, the results will correctly differ
View reconstruct_etc_passwd.c
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <string.h>
#include <unistd.h>
int
main (int argc, char *argv[])
{
const int s = 4096;
@mirekfranc
mirekfranc / breakpoint.py
Created Apr 24, 2015
how to process gdb breakpoints in python
View breakpoint.py
# https://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html
# https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Breakpoint-Commands.html
def my_breakpoint_handler (event):
if (isinstance(event, gdb.BreakpointEvent) and (event.breakpoint.location == "g")):
print event.breakpoint.hit_count
gdb.events.stop.connect(my_breakpoint_handler)
gdb.execute("start")
gdb.execute("break g")
@mirekfranc
mirekfranc / users_and_their_shells.cpp
Created Apr 24, 2015
Which user uses which shell on unix in C++11
View users_and_their_shells.cpp
#include <iostream>
#include <map>
#include <string>
#include <sys/types.h>
#include <pwd.h>
int
main (int argc, char *argv[])
{
std::map<std::string, std::string> nameshell;
@mirekfranc
mirekfranc / colors_in_terminal.py
Last active Aug 29, 2015
How to do colors in terminal from within python script
View colors_in_terminal.py
#!/usr/bin/env python
import sys, os
from collections import namedtuple
Color = namedtuple ("Color", "PURPLE CYAN DARKCYAN BLUE GREEN YELLOW RED BOLD UNDERLINE END")
color = Color ('\033[95m', '\033[96m', '\033[36m', '\033[94m', '\033[92m', '\033[93m', '\033[91m', '\033[1m', '\033[4m', '\033[0m')
def main ():
@mirekfranc
mirekfranc / time_format.py
Created Apr 24, 2015
HH:MM:SS time formatting
View time_format.py
def time_format (seconds):
m, s = divmod (seconds, 60)
h, m = divmod (m, 60)
if h:
return "{0:2}:{1:02}:{2:02}".format (h, m, s)
elif m:
return "{0:5}:{1:02}".format (m, s)
else:
return "{0:8}".format (s)
@mirekfranc
mirekfranc / goto_and_destructors.cpp
Created Apr 24, 2015
goto before construction causes destruction; guaranteed by the C++ standard
View goto_and_destructors.cpp
#include <iostream>
class A
{
public:
A () { std::cout << "a"; }
~A () { std::cout << "A"; }
};
int i = 1;
@mirekfranc
mirekfranc / containter_access.cpp
Created Apr 24, 2015
dispatch based on type of the iterator the container supports
View containter_access.cpp
#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <forward_list>
#include <iterator>
template<typename C>
@mirekfranc
mirekfranc / report_sizes.c
Created Apr 24, 2015
Report file sizes :)
View report_sizes.c
#include <sys/stat.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
struct stat t;
while (*++argv != NULL)
{
You can’t perform that action at this time.