Skip to content

Instantly share code, notes, and snippets.

@avioli
avioli / main.dart
Created Dec 16, 2020
An example of a CupertinoDatePicker widget with a controller
View main.dart
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
@avioli
avioli / colour_contrast.php
Created Nov 10, 2020
A set of PHP functions to help get either white or black colour for foreground text over a given background
View colour_contrast.php
<?php
/**
* Determine if a black or white foreground color will have a better contrast
* ratio for a given background color
*
* @param string|int $bg_r A hex representation of the color
* or the value of the red color 0-255
* @param int $bg_g The value of the green color 0-255
* @param int $bg_b The value of the blue color 0-255
*
@avioli
avioli / git-freeze
Created Oct 1, 2020
Packages all current commits into a tar.gz archive and deletes all git tracked files (beware - deletes empty and untracked dirs, but leaves untracked files)
View git-freeze
#!/usr/bin/env bash
git diff --name-status --exit-code >/dev/null
[[ "$?" == "1" ]] && { echo " --- found uncommited changes"; exit 1; }
echo "removing all git files and packaging .git dir into an archive"
set -e
git ls-files | while read f; do test -f "$f" && echo "$f"; done | xargs -n 30 -- rm -f
find . -type d -empty -delete
tar czf bare.tar.gz .git
rm -rf .git
echo "#!/bin/bash" > revive.sh
View Logger.js
import EventEmitter from 'EventEmitter'; // from https://www.npmjs.com/package/event-emitter
const create = Object.create;
const defineProperties = Object.defineProperties;
const _loggers = new Map();
// Use a [Logger] to log debug messages.
//
// [Logger]s are named using a hierarchical dot-separated name convention.
@avioli
avioli / friendly_id.dart
Created Sep 22, 2020
Generates and decodes an unique invoice id, which can use characters to shorten its length.
View friendly_id.dart
// Author: Evo Stamatov
// September 2020
//
// Python implementation by Will Hardy (December 2008)
// @source: https://github.com/simonluijk/django-invoice/blob/7d136e8b732aa76bab3cc4b5d81a8ce2734571fc/invoice/utils/friendly_id.py
import 'dart:math' as math;
/// Generates and decodes an unique invoice id, which can use characters
/// to shorten its length.
@avioli
avioli / main.dart
Created Sep 8, 2020
dart: filter shortcodes
View main.dart
String filterShortcodes(String input,
{String opening = '[', String closing = ']'}) {
assert(opening.runes.length == 1);
assert(closing.runes.length == 1);
final openingRune = opening.runes.first;
final closingRune = closing.runes.first;
bool filter = false;
final buf = StringBuffer();
for (final rune in input.runes) {
if (filter == false && rune == openingRune) {
@avioli
avioli / generate-icons.gh
Last active Aug 27, 2020
A simple bash script to generate iOS icons
View generate-icons.gh
#!/bin/bash
# Requirements
# - bc - for some math
# - convert - from ImageMagick (or any alternative that provides `convert` util with -resize param)
# - optipng - to optimize the output from convert
# - jq - to read Contents.json if no GEN_SIZES
# Usage:
# ------
@avioli
avioli / animated_map_controller.dart
Last active Aug 25, 2020
A helper to animate a flutter_map's MapController
View animated_map_controller.dart
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart' show MapController;
import 'package:latlong/latlong.dart';
// ////////////////////////////////////////////////////////////////////////////
class AnimatedMapController {
/// Creates an animated MapController
AnimatedMapController({
@required this.mapController,
@avioli
avioli / synology_find_dupl_photos.sh
Last active Jan 11, 2020
Find duplicate photos in my massive photos library
View synology_find_dupl_photos.sh
#!/usr/bin/bash
set -e
cd /volume1/photo/
echo "scanning the photo dir - computing hashes"
# Scan the photo dir.
#
# My collection is on a Synology NAS so it has an @eaDir that holds
@avioli
avioli / release.sh
Created Oct 10, 2019 — forked from rodydavis/release.sh
Flutter Release Script with Fastlane
View release.sh
#!/bin/bash
echo "App Release Automator by @rodydavis"
action="$1"
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
if [ ${action} = "build" ]; then