Skip to content

Instantly share code, notes, and snippets.


Jonas Finnemann Jensen jonasfj

View GitHub Profile
jonasfj / entropy.dart
Created Apr 24, 2021
How compute shannon entropy of a string in Dart.
View entropy.dart
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import 'dart:math';
double entropy(String s) {
final length = s.length.toDouble();
// TODO: Explore if this could be done faster without any allocations, since strings are often short.
final frequencies = <int, int>{};
jonasfj / main.dart
Created May 28, 2020
Sample Dart program that handles `sigint`.
View main.dart
// Copyright 2020 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import 'dart:async';
import 'dart:io';
Future<void> main() async {
var count = 0; {
jonasfj /
Created Jan 20, 2020
Notes on how to query all pubspecs on ``.

Query pubspec.yaml for all packages

When considering introduction of a new field in pubspec.yaml, or wondering how many packages use a certain feature, it can be useful to query all pubspecs from The following notes have some scripts to make this easy.


Helper script to convert YAML to JSON.

jonasfj / count_mono_repo_pub_packages.dart
Created Oct 6, 2019
Count the number of packages on that uses package:mono_repo.
View count_mono_repo_pub_packages.dart
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import 'dart:async' show FutureOr;
import 'dart:async';
import 'dart:convert' show utf8, json;
import 'dart:io' show Directory, Process, IOException, File;
import 'package:http/http.dart' as http;
import 'package:retry/retry.dart' show retry;
import 'package:pool/pool.dart' show Pool;

Two simple test files for

  1. Run dart download.dart
  2. Run dart extract.dart

Have fun..

jonasfj / grpc_googleapis_example.dart
Created Jan 23, 2019
Example of how to generate GRPC APIs from protobufs and use them in Dart.
View grpc_googleapis_example.dart
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
// Experiments with dart, grpc and googleapis
// ==========================================
// 1. Install `protoc`
// 2. `pub global activate protoc_plugin`
// 3. `git clone`
// 4. `protoc --dart_out=grpc:lib/src/generated -I googleapis/ -I /usr/local/include/ googleapis/google/cloud/vision/v1/image_annotator.proto`
import requests
from relengapi.lib.permissions import p
def scope_satisfied(req, scopes):
Returns true, if scopes satisfies req
return any((
s == req or (s.endswith('*') and req.startswith(s[:-1])) for s in scopes
View yubikey-setup.txt
Decent links:
* Or just google for gpg, yubikey, ssh, there is a lot of guides.
## The GPG setup
jonasfj / signin-aws
Created Nov 8, 2017
A simple script for forcing 2FA usage with AWS credentials
View signin-aws
# This script expects AWS credentials:
# And optionally the TOTP entry name in your yubikey
# Put these environment variables into your .bashrc.local (or .bashrc, if you
# don't sync dot-files). In your .bashrc you'll also want:
# alias signin-aws='eval `signin-aws`'