Skip to content

Instantly share code, notes, and snippets.

View sebastianknopf's full-sized avatar

Sebastian Knopf sebastianknopf

View GitHub Profile
@sebastianknopf
sebastianknopf / PermissionsActivity.java
Last active October 29, 2018 10:31
simple practice for requesting dangerous permissions at runtime in android app
// package ... ;
// import ... ;
/*
* Since Android M has been introduced, apps have the possibility to request critical
* permissions at runtime - the Android Support Library provides several
* methods to achieve this.
* This gist is a simple example activitiy to show how to request the critical
* location permission from a simple android app at runtime.
*/
@sebastianknopf
sebastianknopf / OsmSample.java
Created October 29, 2018 19:05
using osmdroid without external storage permission
// activity code goes here
// ...
/*
* To avoid the normally required permission ACCESS_EXTERNAL_STORAGE the osmdroid library
* offers a way to change the base path and the caching path to any other directory.
* We change these directories before initializing our MapView object, so osmdroid
* will NOT need the permission called above.
*
* Note that directories are also objects of type File in Java!
@sebastianknopf
sebastianknopf / CurrentLocationOverlay.java
Last active November 2, 2018 10:26
custom current location overlay for osmdroid
package // ... ;
import org.osmdroid.views.overlay.Overlay;
final class CurrentLocationOverlay extends Overlay implements LocationListener {
private MapView mapView;
private LocationManager locationManager;
private boolean followLocation = true;
private String locationProvider;
@sebastianknopf
sebastianknopf / timetable.php
Created February 5, 2019 14:47
simple script for creating visual time tables based on data in gtfs format
<?php
// database credentials
define('DB_HOST', '');
define('DB_USER', '');
define('DB_PASW', '');
define('DB_DATA', '');
define('DB_PREF', '');
// several constants
@sebastianknopf
sebastianknopf / ExpansionState.java
Created March 10, 2019 16:26
simple algorithm for storing and re-storing the expansion state of a treeview in javafx
import java.util.HashMap;
import java.util.Map;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
public class ExpansionState {
private TreeView treeView;
private Map<Integer, Object> expansionGraph;
@sebastianknopf
sebastianknopf / date_time_compact.c
Last active March 21, 2019 11:06
simple and effective way to store date / time in only 4 byte
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
short date_compress(int day, int month, int year) {
short d = ((((year % 100) << 4) + month) << 5) + day;
return d;
}
int* date_decompress(int cdate) {
@sebastianknopf
sebastianknopf / JwtAuthentication.php
Created July 10, 2019 21:06
Using JwtAuthenticator in CakePHP's Authentication Plugin
// to use the JwtAuthenticator in a CakePHP application you first have load the corresponding
// authenticator in your Application::getAuthenticationService(...)
$service->loadAuthenticator('Authentication.Jwt', [
'returnPayload' => false
]);
// The parameter 'returnPayload' is set to true by default - If you want your visitor using the JWT run trough a full authentication
// process, you should set it to false.
@sebastianknopf
sebastianknopf / lib_gpio.php
Created November 18, 2019 06:53
Control Raspi GPIO with PHP
<?php
define('GPIO_HIGH', 1);
define('GPIO_LOW', 0);
function gpio_exec($cmd)
{
$output = array();
$return = 0;
@sebastianknopf
sebastianknopf / MatrixImage.java
Last active March 18, 2020 20:48
Convert a ZXing BitMatrix to an JavaFX Image
import com.google.zxing.common.BitMatrix;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
/**
* Helper class for converting a com.google.zxing.common.BitMatrix into an Image object instance in JavaFX.
*/
@sebastianknopf
sebastianknopf / CommandLineParser.java
Last active May 25, 2020 10:53
a basic parser for command line arguments in java
import java.util.ArrayList;
import java.util.List;
/**
* Command line argument parser class for parsing command lines like
* program.jar -i input.txt -o output.txt --verbose.
*/
public class CommandLineParser {
/**