Skip to content

Instantly share code, notes, and snippets.

@jiahaog
jiahaog / main.dart
Created April 25, 2024 02:59
Keeping state when widget is repositioned
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
@jiahaog
jiahaog / main.dart
Created April 16, 2024 08:38
ListView vs SingleChildScrollView
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const n = 10;
@jiahaog
jiahaog / main.dart
Created November 18, 2020 23:57
Dart unhandled exception
void main() async {
try {
await Future(() {
Future(() {
throw 'foo';
});
print('future completed');
});
} catch (e) {
@jiahaog
jiahaog / exiftool.md
Created September 20, 2019 05:09
Exiftool

Get names of all geotagged photos with Exiftool:

find . -type f -exec sh -c "exiftool {} -GPSLatitude | grep 'GPS' 2>&1 >/dev/null"  \; -print >> withgps.txt

Move them to another directory:

cat withgps.txt | xargs -I '{}' mv {} with_gps/
@jiahaog
jiahaog / rust_wasm_bootstrap
Last active January 22, 2019 06:22
Install Rust with wasm-pack (useful for CI bootstrap)
#!/usr/bin/env bash
set -euo pipefail
curl https://sh.rustup.rs -sSf | sh -s - -y
export PATH=$HOME/.cargo/bin:$PATH
cargo install wasm-pack
#![allow(dead_code)]
// Using Rust without NLL (2015 edition)
// Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=b30d40f9558112878ba526cbaa6b27fc
fn consume<T>(_: T) {}
struct SimpleStruct {}
fn borrow_simple(_: &SimpleStruct) -> SimpleStruct {
@jiahaog
jiahaog / .gitlab-ci.yml
Created January 31, 2018 08:26
Generic way to build docker images on GitLab
# Drop this file into GitLab repos containing a Dockerfile at the root
image: docker:1.12.3
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
@jiahaog
jiahaog / hash.cabal
Created December 6, 2017 15:34
MD5 Hex Representation in Haskell
build-depends: base >= 4.7 && < 5
, base16-bytestring
, bytestring
, cryptohash-md5

Keybase proof

I hereby claim:

  • I am jiahaog on github.
  • I am jiahaog (https://keybase.io/jiahaog) on keybase.
  • I have a public key ASAnzRnL5FxfaHCJ_M4O1HsYS_yzzBKTo5sHDrBRpU3t6wo

To claim this, I am signing this object:

@jiahaog
jiahaog / transactions.go
Created June 22, 2017 16:10
Simulating transactions in Go
package main
// This file attempts to simulate trasactions, that can be used to run tasks in a chain and
// rollback everything if the chain fails. For example, this can be used to simulate a database
// transaction to clean up dirty data.
// While I am aware that this abstraction is not truely a atomic transaction as it does not
// obtain locks on the affected objects, it is sufficient for our use cases to cleanup dirty data
const txLogTag = "transaction"