Skip to content

Instantly share code, notes, and snippets.

Darcy Liu darcyliu

View GitHub Profile
@darcyliu
darcyliu / web.go
Created Apr 8, 2020
Go web starter
View web.go
package main
import (
"net/http"
"fmt"
"log"
"flag"
"net"
"time"
"runtime"
View UIImage+Helpers.m
@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 Sep 4, 2019
List all image names and class names
View ClassesList.m
#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]);
View hello.cpp
// 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 Jul 2, 2019
Clang constructor and destructor attributes
View attribute.c
// 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 Nov 6, 2018
Objective-C Priority Queue
View PriorityQueue.h
//
// 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 Apr 8, 2020
WebDAV server in go
View files.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 Aug 28, 2017
Retrieve OpenCL Information on OSX
View clinfo.m
//
// 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
@darcyliu
darcyliu / definition.m
Created Aug 18, 2017
OSX dictionary definition lookup
View definition.m
// Command-line dictionary lookup.
//
// Build with:
// clang -framework CoreServices
// clang -fobjc-arc -fmodules definition.m -o definition
#import <CoreFoundation/CoreFoundation.h>
#import <CoreServices/CoreServices.h>
@darcyliu
darcyliu / proxy.js
Created May 10, 2017
Simple HTTP Proxy
View proxy.js
var http = require('http');
var net = require('net');
var url = require('url');
function onRequest(request, response) {
console.log('request: ' + request.url);
var u = url.parse(request.url);
var options = {
hostname: u.hostname,
You can’t perform that action at this time.