Skip to content

Instantly share code, notes, and snippets.

@darcyliu
darcyliu / setup-wireguard.sh
Created December 31, 2023 08:17
Setup WireGuard on FreeBSD
pkg install -y wireguard wireguard-tools
cd /usr/local/etc/wireguard/
umask 077
wg genkey > freebsd.private
wg pubkey < freebsd.private > freebsd.public
wg genkey > client.private
wg pubkey < client.private > client.public
@darcyliu
darcyliu / install-kubernetes-on-buster.sh
Last active March 3, 2024 22:54 — forked from BeerOnBeard/install-kubernetes-on-buster.sh
Set up a single-node Kubernetes system on Debian 10 (Bustomer). Use Flannel as the network fabric. Install the Kubernetes dashboard.
#!/bin/bash
set -e;
# Set up a single-node Kubernetes system on Debian 10 (Buster).
# Use Flannel as the network fabric. Install the Kubernetes
# dashboard.
# disable swap
swapoff -a;
@darcyliu
darcyliu / web.go
Created April 8, 2020 14:27
Go web starter
package main
import (
"net/http"
"fmt"
"log"
"flag"
"net"
"time"
"runtime"
@darcyliu
darcyliu / UIImage+Helpers.m
Created December 25, 2019 06:28
Image Resizing
@implementation UIImage (Helpers)
- (UIImage *)scaleImageToSize:(CGSize)newSize
{
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:newSize];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext*_Nonnull myContext) {
[self drawInRect:(CGRect) {.origin = CGPointZero, .size = newSize}];
}];
return image;
}
@darcyliu
darcyliu / ClassesList.m
Created September 4, 2019 09:18
List all image names and class names
#import <objc/runtime.h>
NSArray *AllImageNames() {
unsigned int imageCount = 0;
const char **imageNames = objc_copyImageNames(&imageCount);
NSMutableArray<NSString *> *imageNameStrings = [[NSMutableArray alloc] initWithCapacity:imageCount];
if (imageNames!=NULL) {
for (unsigned int i = 0; i < imageCount; i++){
const char *imageName = imageNames[i];
NSLog(@"image name: %s", imageNames[i]);
@darcyliu
darcyliu / hello.cpp
Created July 2, 2019 05:30
mutex example
// mutex example
// clang++ hello.cpp -std=c++11 -o hello
#include <iostream> // std::cout
#include <thread> // std::thread
#include <mutex> // std::mutex
std::mutex mtx; // mutex for critical section
void print_block (int n, char c) {
// critical section (exclusive access to std::cout signaled by locking mtx):
@darcyliu
darcyliu / attribute.c
Created July 2, 2019 05:27
Clang constructor and destructor attributes
// clang attribute.c -o attribute
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello World!\n");
return 0;
}
__attribute__((constructor)) static void beforeFunction()
{
printf("beforeFunction\n");
@darcyliu
darcyliu / PriorityQueue.h
Last active November 6, 2018 03:07
Objective-C Priority Queue
//
// PriorityQueue.h
// PriorityQueue
//
// Created by Darcy Liu on 2018/11/6.
// Copyright © 2018 Darcy Liu. All rights reserved.
//
#import <Foundation/Foundation.h>
@darcyliu
darcyliu / files.go
Last active December 3, 2021 15:17
WebDAV server in go
// go get golang.org/x/net/webdav
// go run files.go -openbrowser -http=127.0.0.1:9090
package main
import (
"context"
"flag"
"net/http"
"log"
"fmt"
@darcyliu
darcyliu / clinfo.m
Created August 28, 2017 09:59
Retrieve OpenCL Information on OSX
//
// clinfo.m
// clinfo
//
// Created by Darcy Liu on 26/08/2017.
// Copyright © 2017 Darcy Liu. All rights reserved.
//
// clang -fobjc-arc -fmodules clinfo.m -o clinfo