Skip to content

Instantly share code, notes, and snippets.

View avioli's full-sized avatar

Evo Stamatov avioli

View GitHub Profile
@avioli
avioli / fast_hash.dart
Created March 8, 2024 03:46
Fast hash function in Dart
/// FNV-1a 64bit hash algorithm optimized for Dart Strings
int fastHash(String string) {
var hash = 0xcbf29ce484222325;
var i = 0;
while (i < string.length) {
final codeUnit = string.codeUnitAt(i++);
hash ^= codeUnit >> 8;
hash *= 0x100000001b3;
hash ^= codeUnit & 0xFF;
@avioli
avioli / main.dart
Created December 16, 2020 00:05
An example of a CupertinoDatePicker widget with a controller
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 November 10, 2020 23:55
A set of PHP functions to help get either white or black colour for foreground text over a given background
<?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 October 1, 2020 05:32
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)
#!/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
@avioli
avioli / Logger.js
Created September 29, 2020 06:01
A clone of https://pub.dev/packages/logging in JavaScript
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 September 22, 2020 23:31
Generates and decodes an unique invoice id, which can use characters to shorten its length.
// 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 September 8, 2020 10:34
dart: filter shortcodes
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 August 27, 2020 08:29
A simple bash script to generate iOS icons
#!/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 February 28, 2023 19:18
A helper to animate a flutter_map's MapController
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,