Skip to content

Instantly share code, notes, and snippets.

View janpipek's full-sized avatar
🤔
...

Jan Pipek janpipek

🤔
...
View GitHub Profile
@janpipek
janpipek / bytes.cpp
Created June 13, 2012 07:57
How to print byte representation of a simple struct in C++
#include <iostream>
struct a
{
int b;
double c;
};
using namespace std;
int main()
@janpipek
janpipek / no-return-value.c
Created June 13, 2012 08:05
Different implicit return values when compiled using gcc and g++
// gcc no-return-value.c --- prints 0
// g++ no-return-value.c --- prints a random 32-bit integer
// (using gcc 4.4)
#include "stdio.h"
int a() { }
int main() {
printf("%d", a());
}
@janpipek
janpipek / get-public-ip.rb
Created June 13, 2012 19:03
tell your current public IP using ruby
#!/usr/bin/ruby
# This script prints your current public IP
#
# It retrieves it using http://checkip.dyndns.org web page.
# If given a parameter, it treats it as (float) number of seconds
# before timeout. The default timeout is set to 10 seconds.
#
# Author: Jan Pipek (jan.pipek AT gmail.com)
@janpipek
janpipek / python_constructors.py
Created August 21, 2012 12:57
Inheritance and constructors in Python
#!/bin/env/python
# How inheritance of constructors in python works.
# Only simple cases without multiple inheritance are covered.
class A(object):
"""No inheritance"""
def __init__(self):
print "A"
class B(A):
@janpipek
janpipek / prime.cpp
Created November 13, 2012 20:40
Templated primality test in C++
#include <iostream>
#include <sstream>
#include <cmath>
#include <climits>
const int DEPTH = 7;
// Reasonable values are 3,5,7. However the 7 version takes a very long time to compile (a few minutes).
// Use g++ -O3 prime.cpp if possible.
using namespace std;
@janpipek
janpipek / .hgignore
Last active June 20, 2019 05:39
.hgignore template
syntax: glob
# Back-up
*~
# Executables
**/build/**
*.o
.depend
@janpipek
janpipek / input-storage.js
Created June 19, 2013 09:56
Auto-store state of input elements in localStorage (jQuery)
/**
* Simple jQuery utility for saving element values in localStorage.
*
* Usage:
* - Add class "store-state" to the element you want to save.
* - Add id attribute to the element or specify your own storage key (attribute data-storage-name)
* - Add attribute "data-storage-name" to the element if you
* want to control under which name the value will be stored
* - Add attribute "data-storage-noload" to suppress loading (will be stored though, it is
* useful, when HTML-specified value is temporarily more important).
@janpipek
janpipek / sublime_load_package.py
Last active August 29, 2015 13:56
Load python package in sublime (version 2/3)
#!/usr/bin/env python
import sys
import pkgutil
import os
if len(sys.argv) != 2:
print("Usage: sublime_load.py <package-name>")
else:
package = sys.argv[1]
loader = pkgutil.find_loader(package)
@janpipek
janpipek / recompress_hdf5.py
Last active June 16, 2021 06:13
Create a copy of HDF5 with compressed everything that could be compressed.
import h5py
import os
def _report(operation, key, obj):
type_str = type(obj).__name__.split(".")[-1].lower()
print "%s %s: %s." % (operation, type_str, key)
def h5py_compatible_attributes(in_object):
'''Are all attributes of an object readable in h5py?'''
try:
@janpipek
janpipek / autoreload.py
Created July 29, 2014 13:29
autoreload in IPython
%load_ext autoreload
%aimport module_to_be_reload # Select modules to be reloaded
%autoreload 1 # Set that we want only the listed modules