Skip to content

Instantly share code, notes, and snippets.

@DaoWen
DaoWen / qmk-compile
Last active February 15, 2022 17:47
Helper script for compiling Sonix QMK firmware using a Docker container
#!/bin/bash
set -e
if [[ "$1" == --help ]]; then
echo 'Usage:' >&2
echo " $0 [KEYBOARD] [KEYMAP]" >&2
exit 0
fi
@DaoWen
DaoWen / MyBot.scala
Last active October 9, 2017 14:00
Halite-II starter bot in Scala (using Java starter kit)
import hlt._
import scala.collection.JavaConverters._
object MyBot extends App {
val networking = new Networking
val gameMap = networking.initialize("ScalaBot")
def navHelp(ship: Ship, planet: Planet): Option[Move] = {
if (ship canDock planet) Some {
@DaoWen
DaoWen / ExampleTestSuite.scala
Created September 27, 2017 01:58
Example of simple JUnit4 tests in Scala, including exception checking via @test(expected).
import org.junit.Assert._
import org.junit.Test
class ExampleTestSuite {
@Test
def ok() {
assertTrue(true)
}
@DaoWen
DaoWen / docker-cleanup
Created September 11, 2017 14:42
Clean up inactive docker instances and images
#!/bin/bash
# Remove unused instances
dead_instances="$(docker ps -aq -f status=exited)"
[ "$dead_instances" ] && docker rm $dead_instances
# Remove unused images
dead_images="$(docker image ls | awk '/^<none> +<none>/ { print $3 }')"
[ "$dead_images" ] && docker rmi $dead_images
@DaoWen
DaoWen / git-tidy
Created May 23, 2017 04:33
Custom git command for tidying up your git repo working copy
#!/bin/bash
#
# Copyright (c) 2017 Nick Vrvilo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@DaoWen
DaoWen / tmux_local_install.sh
Created May 20, 2017 21:06
Script for installing tmux in your home directory (no root)
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $INSTALL_PREFIX/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=2.2
@DaoWen
DaoWen / sysadmin_day.ics
Created May 2, 2017 03:12 — forked from artem-bez/sysadmin_day.ics
iCalendar file that describes when to celebrate the SysAdmin Appreciation Day. Celebration happens annually on the last Friday of July. You can import this file into a calendar application that doesn't provide direct means to specify such recurrence rule. For example, Google Calendar is one of such apps.
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART;VALUE=DATE:20000728
DTEND;VALUE=DATE:20000728
RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=7;BYDAY=-1FR
DESCRIPTION:https://en.wikipedia.org/wiki/System_Administrator_Appreciation_Day http://sysadminday.com/
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:SysAdmin Appreciation Day
@DaoWen
DaoWen / tmux_local_install.sh
Created November 10, 2016 19:31
tmux install script
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $INSTALL_PREFIX/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=2.2
@DaoWen
DaoWen / fcontext.h
Last active November 1, 2016 02:45
C header file providing the interface for the Boost.Context assembly routines
/**
* Link code against the correct versions of the jump*.S and make*.S files
* from https://github.com/boostorg/context/tree/develop/src/asm.
*
* These function prototypes are based on those in fcontext.hpp, at
* https://github.com/boostorg/context/blob/develop/include/boost/context,
* which includes the following copyright notice:
*
* Copyright Oliver Kowalke 2009.
* Distributed under the Boost Software License, Version 1.0.
@DaoWen
DaoWen / fib-threads.c
Last active March 29, 2017 06:30
consistently segfaults in pthread_create on os x but not on linux
#include <assert.h>
#include <pthread.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#define N 10