This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the correct number of arguments are provided | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <database_name> <user_name>" | |
exit 1 | |
fi | |
# Command-line arguments | |
DB_NAME="$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OS release info | |
uname -s | |
uname -r | |
uname -n | |
# Start up time | |
uptime | |
# CPU info | |
cat /proc/stat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"fmt" | |
"log" | |
"flag" | |
"net" | |
"time" | |
"runtime" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PriorityQueue.h | |
// PriorityQueue | |
// | |
// Created by Darcy Liu on 2018/11/6. | |
// Copyright © 2018 Darcy Liu. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
NewerOlder