Skip to content

Instantly share code, notes, and snippets.

View GZGavinZhao's full-sized avatar
☯️
See chart in profile for indications of availability.

Gavin Zhao GZGavinZhao

☯️
See chart in profile for indications of availability.
  • 01:54 (UTC -04:00)
View GitHub Profile
@GZGavinZhao
GZGavinZhao / cliexample.v
Last active August 9, 2021 23:53
Blueprint of what an example cli in V should be.
module main
import cli, os
fn main(
mut app := cli.Command{
name: 'pizzahut'
description: 'Cli for ordering pizza from Pizza Hut'
// execute: // Without specifying the `execute` parameter, it will just output the usage message
commands: [
@GZGavinZhao
GZGavinZhao / server.dart
Last active August 25, 2021 08:21
AngularDart Server-Side Rendering Script with Puppeteer
// Put it in your bin folder, build the site, and run `dart run bin/server.dart`
// Go to http://localhost:8080 to see the result! o(^▽^)o
//
// Remember to open in an incognito or guest window, or the browser might use
// the cache instead of letting the server render it (yes FireFox that's you).
import 'dart:io';
// Remember to add these dependencies!
import 'package:mime/mime.dart';
@GZGavinZhao
GZGavinZhao / install-node.sh
Created August 24, 2021 00:59
Install nodejs on M1 Mac without sudo
#!/bin/sh
mkdir -p $HOME/SDK/
curl -o node.tar.gz -L https://nodejs.org/dist/v16.7.0/node-v16.7.0-darwin-arm64.tar.gz
tar -xf node.tar.gz -C $HOME/SDK && rm -rf node.tar.gz
mv node-v16.7.0-darwin-arm64 node
echo "export PATH=$PATH:$HOME/SDK/node/bin" >> $HOME/.zshrc
source $HOME/.zshrc
node --version
@GZGavinZhao
GZGavinZhao / null_coverage.dart
Last active October 5, 2021 16:21
Detect how many files have been migrated to NNBD in a Dart project.
import 'dart:io';
import 'dart:convert';
import 'package:path/path.dart' as p;
main(List<String> args) async {
print('Counting number of Dart files...');
var count = 0;
await Directory('lib').list(recursive: true).forEach((element) {
if (element is File && p.extension(element.path) == '.dart') {
@GZGavinZhao
GZGavinZhao / getchar.dart
Created March 20, 2022 00:30
Fast I/O for competitive programming in Dart by calling getchar() in C.
import 'dart:ffi' as ffi;
typedef getchar_func = ffi.Int8 Function();
final dylib = ffi.DynamicLibrary.open("/usr/lib/libstdc++.so");
final int Function() getChar =
dylib.lookup<ffi.NativeFunction<getchar_func>>('getchar').asFunction();
void main() {
int input = getChar();
// There's no `char` in Dart. Use the following to convert your ASCII value
@GZGavinZhao
GZGavinZhao / main.dart
Created September 2, 2022 01:11
NativeFinalizer work around to free pointers in a guaranteed way without ANY native code
import 'dart:ffi';
import 'package:ffi/ffi.dart';
void main(List<String> arguments) {
print('Opening the executable...');
final lib = DynamicLibrary.executable();
print('Grabbing `free` function from myself...');
final free = lib.lookupFunction<Void Function(Pointer), void Function(Pointer)>('free');
const String test = "Hello World!";
@GZGavinZhao
GZGavinZhao / baskit.d
Created December 26, 2022 14:44
Build order determination for boulder.
import std.stdio, std.array, std.container, std.string, std.file, std.conv, std.algorithm, std.parallelism, std.path;
import moss.deps.dependency;
import moss.format.binary.reader;
import moss.format.binary.payload;
import moss.format.binary.payload.meta;
import moss.format.binary.payload.meta.record_pair;
import moss.format.binary.payload.layout;
void mkuniq(T)(ref T[] arr)
{
@GZGavinZhao
GZGavinZhao / oienv.nix
Created February 10, 2023 02:59
My OI environment
# Nix下的OI环境,主要是为了Haskell
let
# 万一以后需要呢
config = { allowUnfree = true; };
pkgs = import <nixpkgs> { inherit config; };
in {
# Base
@GZGavinZhao
GZGavinZhao / single-commit-clone.d
Created July 6, 2023 00:20
Clone any repo at a particular commit, written in D
module main;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.stdio;
import std.format;
import std.conv;
import std.path;
@GZGavinZhao
GZGavinZhao / main.go
Created December 4, 2023 21:20
Bump release number of a package.yml file.
package main
import (
"bufio"
"bytes"
"fmt"
"os"
"strconv"
"gopkg.in/yaml.v3"