Skip to content

Instantly share code, notes, and snippets.

View hleinone's full-sized avatar

Hannu Leinonen hleinone

View GitHub Profile
@hleinone
hleinone / jQuery-Timepicker-Addon-issue-138.html
Created April 18, 2011 14:19
Demonstrates the issue in jQuery Timepicker Addon when setting a minDate with a time value of 9:25, then the time in that date can not be changed to 10:00 since the minimum minute doesn't get updated after the hour changes.
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css" />
<style type="text/css">
/* css for timepicker */
.ui-timepicker-div .ui-widget-header{ margin-bottom: 8px; }
.ui-timepicker-div dl{ text-align: left; }
.ui-timepicker-div dl dt{ height: 25px; }
.ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
@hleinone
hleinone / ArrayMatrix.java
Created May 16, 2011 08:44
Matrix interface, an array-backed implementation and a JUnit test verifying that it works
package matrix;
import java.util.Arrays;
public class ArrayMatrix<T> implements Matrix<T> {
private Object[][] array;
public ArrayMatrix(int height, int width) {
array = new Object[height][width];
}
@hleinone
hleinone / Unicorn.java
Created February 19, 2013 12:34
Poetic unicorn.
import java.lang.reflect.Field;
import java.util.Random;
/**
* Unicorns may be betray'd with trees.
*/
public class Unicorn {
private static boolean patted = false;
static {
@hleinone
hleinone / redirector.js
Last active August 29, 2015 14:07
Redirector
var redirector = new Object();
redirector.openLink = function(url, playStoreId, appStoreId) {
var isAndroid = navigator.userAgent.match(/Android/),
isIos = navigator.userAgent.match(/iPhone|iPad|iPod/),
isFirefox = navigator.userAgent.match(/Firefox/),
isOpera = navigator.userAgent.match(/OPR/);
if (isAndroid) {
if (isFirefox) {
setTimeout('market://details?id=' + playStoreId);
window.location.replace(url);
@hleinone
hleinone / CreditCardNumberFormattingTextWatcher.kt
Last active November 30, 2023 14:03
Android EditText TextWatcher for formatting credit card number made with Kotlin
class CreditCardNumberFormattingTextWatcher : TextWatcher {
private var current = ""
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun afterTextChanged(s: Editable) {
@hleinone
hleinone / normalize-gpx.js
Created April 25, 2017 06:44
Normalizes GPX file by replacing track points with exactly same coordinate with interpolated values, removing leaps with inhuman speed.
var fs = require("fs");
var xml2js = require("xml2js");
var gpx = process.argv[2];
// https://gist.github.com/wteuber/6241786
Math.fmod = function(a, b) {
return Number((a - (Math.floor(a / b) * b)).toPrecision(8));
};
@hleinone
hleinone / rating_bar.dart
Created August 20, 2018 19:12
Flutter rating bar
import 'dart:math';
import 'package:flutter/material.dart';
class RatingBar extends StatelessWidget {
RatingBar({this.numStars = 5, this.rating = 0.0, this.onChanged});
final int numStars;
final double rating;
final ValueChanged<double> onChanged;
@hleinone
hleinone / OneDp.kt
Created February 4, 2019 14:12
Density pixel calculation helper
import android.content.res.Resources
import android.util.TypedValue
object OneDp {
fun init(resources: Resources) {
oneDp = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, resources.displayMetrics)
}
}
private var oneDp = 0f
@hleinone
hleinone / AlertDialog+Rx.kt
Created February 6, 2019 09:09
Android AlertDialog Rx extension
import android.content.DialogInterface
import androidx.appcompat.app.AlertDialog
import com.jakewharton.rxbinding2.view.clicks
import io.reactivex.Maybe
import io.reactivex.Single
/**
* Sets the dialog non-cancelable. Emits either {@link DialogInterface#BUTTON_POSITIVE},
* {@link DialogInterface#BUTTON_NEGATIVE} or {@link DialogInterface#BUTTON_NEUTRAL} and dismisses
* the dialog.
@hleinone
hleinone / SharedPreferences+Rx.kt
Created February 6, 2019 09:10
Android SharedPreferences Rx extension
import android.content.SharedPreferences
import io.reactivex.Maybe
import io.reactivex.Single
@androidx.annotation.CheckResult
fun SharedPreferences.boolean(key: String, defValue: Boolean): Single<Boolean> = Single.just(getBoolean(key, defValue))
@androidx.annotation.CheckResult
fun SharedPreferences.boolean(key: String): Maybe<Boolean> = Maybe.create { maybeEmitter ->
if (contains(key)) {