Skip to content

Instantly share code, notes, and snippets.

Moor: Sent CREATE TABLE IF NOT EXISTS blood_sugars (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, value INTEGER NOT NULL, date INTEGER NOT NULL, type VARCHAR NOT NULL); with args []
Moor: Sent INSERT INTO blood_sugars (id, value, date, type) VALUES (?, ?, ?, ?) with args [2, 13, 1578779185, some type]
Moor: Sent SELECT * FROM blood_sugars WHERE (CAST(strftime("%Y", date, "unixepoch") AS INTEGER)) = ? AND (CAST(strftime("%m", date, "unixepoch") AS INTEGER)) = ? AND (CAST(strftime("%d", date, "unixepoch") AS INTEGER)) = ?; with args [2020, 1, 11]
[BloodSugar(id: 2, value: 13, date: 2020-01-11 22:46:25.000, type: some type)]
@simolus3
simolus3 / info.md
Last active March 31, 2023 05:22
Analyzer plugin - tips and tricks

Analyzer plugins - tips and tricks

Debugging

Analyzer plugins run in a processes started and managed by the analysis server. This is useful when shipping plugins to users, but unfortunate for us as we can't attach a debugger to the plugin process.

Luckily, we can use a little trick to help us here. For debugging purposes, we instead use the following model. The actual plugin will start a websocket server. When the proxy loaded by the analysis server gets started, it will connect to that server and relay all operations. In fact, almost no code changes are necessary to the plugin.

@simolus3
simolus3 / database.dart
Created August 26, 2019 15:22
Unsucessful attempt at reproducing moor#121
import 'dart:convert';
import 'package:moor_flutter/moor_flutter.dart';
part 'database.g.dart';
@DataClassName("Journal")
class Journals extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text().withLength(min: 1, max: 50)();
TextColumn get description => text().withLength(min: 1, max: 100)();
@simolus3
simolus3 / shopping_cart.dart
Last active November 21, 2023 12:27
Shopping carts in moor
import 'package:moor/moor.dart';
import 'package:moor/moor_vm.dart';
import 'package:rxdart/rxdart.dart';
part 'shopping_cart.g.dart';
class ShoppingCarts extends Table {
IntColumn get id => integer().autoIncrement()();
}
@simolus3
simolus3 / dao.dart
Created August 5, 2019 09:32
Reproduce moor dao issue
import 'package:moor/moor.dart';
import 'database.dart';
part 'dao.g.dart';
@UseDao(tables: [Users])
class SomeDao extends DatabaseAccessor<Database> with _$SomeDaoMixin {
SomeDao(Database db) : super(db);
}
@simolus3
simolus3 / main.dart
Created July 12, 2019 07:31
Download file in dart
import 'dart:convert';
import 'dart:html';
import 'dart:typed_data';
void main() {
final content = '["general kenobi", "you are a bold one"]';
download('message.json', utf8.encode(content) as Uint8List, type: 'application/json');
}
void download(String filename, Uint8List data, {String type = 'octet/stream'}) {
import 'package:moor_flutter/moor_flutter.dart';
part 'database.g.dart';
class Rooms extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get desc => text()();
}
@UseMoor(tables: [Rooms])
@simolus3
simolus3 / main.dart
Created March 28, 2019 18:16
Displays the current balance of a given ethereum address
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
void main() {
runApp(MaterialApp(
home: EthApp(),
theme: ThemeData(
primaryColor: Colors.orange,
typography: Typography(
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.util.Base64;
public class PasswordHasher {
private static final int HASHING_ITERATIONS = 128_000;
@simolus3
simolus3 / add_iteratively.pas
Last active October 13, 2016 12:35
Rekursionsaufgaben
procedure TForm1.btnAddItClick(Sender: TObject);
var sum, i: integer;
begin
sum := 0;
for i := 1 to 4 do begin
sum := sum + (random(6) + 1);
end;
ShowMessage(IntToStr(sum));
end;