Skip to content

Instantly share code, notes, and snippets.

Avatar

Benoit Duffez BenoitDuffez

  • Kerlink
  • Los Angeles greater area, CA, USA
View GitHub Profile
@BenoitDuffez
BenoitDuffez / main.dart
Created May 19, 2021
Dart let extension
View main.dart
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
SO #67577995 let implementation
View main.dart
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();
}
View keybase.md

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:

View Keep Column Sorted in Google Sheets.gs
/**
* 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 Oct 25, 2020
Parse migration failed exception (Android Room)
View mig
#!/bin/bash
# Clean up on exit
function finish {
rm -f expected found
}
trap finish EXIT
# How to parse JSON
JQ="jq --sort-keys"
View bug.sh
#!/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
View gtfs_schema.sql
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)
View fill_database.sh
#!/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}'`
View Watch Moto 360
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"
View gist:9996012
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));