Skip to content

Instantly share code, notes, and snippets.

View BenoitDuffez's full-sized avatar

Benoit Duffez BenoitDuffez

  • Kerlink
  • Los Angeles greater area, CA, USA
View GitHub Profile
@BenoitDuffez
BenoitDuffez / main.dart
Created May 19, 2021 13:29
Dart let extension
import 'package:flutter_test/flutter_test.dart';
extension Let<T extends Object> on T? {
R let<R>(R Function(T) callback, {R Function()? or}) {
var self = this;
if (self != null) {
return callback(self);
}
if (or != null) {
return or();
@BenoitDuffez
BenoitDuffez / main.dart
Last active May 18, 2021 20:51
SO #67577995 let implementation
O let<I extends Object, O>(
I? value,
O Function(I) cb,
{O Function()? or}) {
if (value != null) {
return cb(value);
}
if (or != null) {
return or();
}
@BenoitDuffez
BenoitDuffez / keybase.md
Created February 10, 2020 18:42
Keybase

Keybase proof

I hereby claim:

  • I am benoitduffez on github.
  • I am bduffez (https://keybase.io/bduffez) on keybase.
  • I have a public key ASCGN0rZCXTbxEmeZTl7PnO9UFjMJpE-SrwMk4Zny0WxUQo

To claim this, I am signing this object:

/**
* This Google Sheets script keeps data in the specified column sorted any time
* the data changes.
*
* After much research, there wasn't an easy way to automatically keep a column
* sorted in Google Sheets, and creating a second sheet to act as a "view" to
* my primary one in order to achieve that was not an option. Instead, I
* created a script that watches for when a cell is edited and triggers
* an auto sort.
*
@BenoitDuffez
BenoitDuffez / mig
Last active October 12, 2023 18:52
Parse migration failed exception (Android Room)
#!/bin/bash
# Clean up on exit
function finish {
rm -f expected found
}
trap finish EXIT
# How to parse JSON
JQ="jq --sort-keys"
@BenoitDuffez
BenoitDuffez / bug.sh
Created September 22, 2015 22:41
MySQL bug?
#!/bin/sh
MYSQL="mysql" # add -u xyz -pabcd or export MYSQL_PWD, etc
echo "Init"
$MYSQL -e "drop database if exists test"
$MYSQL -e "create database test"
$MYSQL test -e 'delimiter $$
create function func() returns int(10)
begin
@BenoitDuffez
BenoitDuffez / gtfs_schema.sql
Created September 16, 2014 08:11
GTFS Tables Schema
CREATE TABLE `agency` (
transit_system VARCHAR(50) NOT NULL,
agency_id VARCHAR(100),
agency_name VARCHAR(255) NOT NULL,
agency_url VARCHAR(255) NOT NULL,
agency_timezone VARCHAR(100) NOT NULL,
agency_lang VARCHAR(100),
agency_phone VARCHAR(100),
agency_fare_url VARCHAR(100),
PRIMARY KEY (agency_id)
@BenoitDuffez
BenoitDuffez / fill_database.sh
Last active August 29, 2015 14:06
GTFS playground
#!/bin/bash
. mysql.ini
schema_url="https://raw.githubusercontent.com/mauryquijada/gtfs-mysql/master/gtfs-sql.sql"
mysqlexec="mysql -h $host -u $user -p${pass} $name"
datafolder="./data"
provider_url="http://www.data.gouv.fr/en/dataset/offre-transport-de-la-ratp-format-gtfs-ratp"
# List files that are available from the provider
files=`curl -s $provider_url | egrep -o 'data-url="[^"]+"' | awk -F\" '{print $2}'`
watch -n 60 "curl -s https://play.google.com/store/devices?hl=en | tr '<' '\n' | tr '\240' ' ' | grep 'cover-image' | grep -oE 'alt=\"[^\"]+\"' | cut -c6\- | sed -e 's/.$//' | sort"
public static String getDeltaDateText(Context context, Calendar date) {
final String formattedDate;
if (date != null && date.getTimeInMillis() > 10000) {
long delta = (new GregorianCalendar().getTimeInMillis() - date.getTimeInMillis()) / 1000;
if (delta < 60) {
formattedDate = context.getString(R.string.time_delay_moments);
} else if (delta < 3600) {
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_minutes), (int) (delta / 60));
} else if (delta < 3600 * 24) {
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_hours), (int) (delta / 3600));