Skip to content

Instantly share code, notes, and snippets.

@tcd93
tcd93 / pkcs10Generator.js
Created April 22, 2020 03:26
Simple way to generate certificate signing request (CSR) with X.509 using Javascript
import * as asn1js from 'asn1js';
import { getCrypto, getAlgorithmParameters, CertificationRequest, AttributeTypeAndValue } from 'pkijs/build'
import { arrayBufferToString, toBase64 } from 'pvutils';
//https://github.com/PeculiarVentures/PKI.js/blob/31c10e9bb879cac59d710102adf4fd7bd61cd66c/src/CryptoEngine.js#L1300
const hashAlg = 'SHA-256'
const signAlg = 'ECDSA'
/**
* @example
* createPKCS10({ enrollmentID: 'user1', organizationUnit: 'Marketing', organization: 'Farmer Market', state: 'M', country: 'V' })
@tcd93
tcd93 / BinaryTreeCompare.go
Last active September 17, 2020 07:32
Compare two binary trees using Goroutines
package main
// solution to exercise from https://tour.golang.org/concurrency/7
// if running local, execute `go get golang.org/x/tour/tree` beforehand
import (
"fmt"
"golang.org/x/tour/tree"
)
@tcd93
tcd93 / main.dart
Last active December 14, 2020 05:10
Draggable widget fails on Web
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final overlayCtnKey = GlobalKey();
@override
@tcd93
tcd93 / flutter_buttons.dart
Last active January 19, 2021 04:06
Flutter inconsistent button colors
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@tcd93
tcd93 / game-of-life.py
Created February 24, 2021 08:12
Conway's game of life in python (numpy)
import numpy as np
from numpy.lib.shape_base import expand_dims
def add_walls(board) -> np.ndarray:
'''add 2 rows & columns around the board
@param board: numpy 2d array
@return: a new board
'''
h, w = board.shape # get heigh & width
# now sandwich it!
@tcd93
tcd93 / main.dart
Created March 4, 2021 03:14
Dart Completer sample
import 'dart:async';
import 'dart:math';
class API {
void startMethod() {
Timer(Duration(seconds: 2), onMethodDone);
}
bool onMethodDone() {
final randomBool = Random().nextBool();
@tcd93
tcd93 / datetime_parse2.dart
Last active March 23, 2021 10:13
datetime.parse2
void main() {
var s = 'Thu Jan 32 23:39:59 2021+444';
var t = parse2(s);
print(t);
}
DateTime parse2(String formattedString) {
final re = RegExp(r'^(\w{3}) ' // weekday
r'(\w{3}) ' // month
r'(\d{2}) ' // day in month
@tcd93
tcd93 / README.md
Last active September 8, 2023 09:38
Guide to run Flutter inside Window's WSL2 (Ubuntu 11)

Works with Flutter 3.13 on Windows 11 (with Ubuntu 22.04 on WSL2)

  1. Install Ubuntu 22.02 on Microsoft Store
  2. Login Ubuntu
  3. Install Android-sdk
    sudo apt-get update
    sudo apt-get install android-sdk
    export ANDROID_HOME=/usr/lib/android-sdk