Skip to content

Instantly share code, notes, and snippets.

@flowerinthenight
flowerinthenight / func_name_prefix.go
Last active August 26, 2016 19:07
And function name prefix to logs in Go.
package main
import (
"fmt"
"log"
"regexp"
"runtime"
)
func traceln(v ...interface{}) {
@flowerinthenight
flowerinthenight / expvar_mux.go
Last active November 15, 2019 10:28
Serving expvar when using gorilla/mux.
package main
import (
"expvar"
"log"
"net/http"
"github.com/gorilla/mux"
)
@flowerinthenight
flowerinthenight / directory_cleaner.go
Last active August 26, 2016 19:11
A simple directory cleanup tool for Windows.
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"os/exec"
"time"
)
@flowerinthenight
flowerinthenight / syslog_log.go
Last active August 26, 2016 19:18
Output Go's log function to syslog.
package main
import (
"log"
"log/syslog"
"os"
)
func main() {
trace, err := syslog.New(syslog.LOG_INFO, "myapp")
@flowerinthenight
flowerinthenight / signal_handler.cpp
Created August 26, 2016 19:24
A simple signal handler in C++.
#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <sys/file.h>
// signal handler
void signal_handler(int s)
{
std::cout << "Caught signal: " << s << std::endl;
exit(1);
@flowerinthenight
flowerinthenight / file_folder_watch.ps1
Last active April 7, 2021 22:51
A simple file/folder watcher script in Powershell.
Param($MonitorFolder, $SleepInSec)
if (!$MonitorFolder) {
Write-Host "You need to set -MonitorFolder parameter."
Return
}
$sleep = 1
if ($SleepInSec) {
$sleep = $SleepInSec
@flowerinthenight
flowerinthenight / rest_client_svr_console.cs
Last active September 18, 2022 10:12
A simple REST client/server console app in C#.
using CommandLine;
using CommandLine.Text;
using Grapevine;
using Grapevine.Client;
using Grapevine.Server;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
; Defines
#define MyAppVersion "1.0.0"
#define MyAppVersionInfoVersion "1.0.0"
#define MyAppName "My Superb App That Will Save The World"
#define MyAppPublisher "Superb, Inc."
#define MyAppURL "http://www.a-very-superb-url-to-my-app.com/"
#define MyAppCopyright "Copyright (C) Copyright 3056. All rights reserved."
#define MyAppId "{{88C6A6D9-324C-46E8-BA87-563D14021442}"
#define MyAppPath "{pf}\Superb\WorldSavingApp"
#include <Windows.h>
BOOL TouchInput(POINTER_FLAGS pointerFlags, int x, int y)
{
POINTER_TOUCH_INFO contact = { 0 };
contact.pointerInfo.pointerType = PT_TOUCH;
contact.pointerInfo.pointerFlags = pointerFlags;
contact.pointerInfo.ptPixelLocation.x = x;
contact.pointerInfo.ptPixelLocation.y = y;
contact.pointerInfo.pointerId = 0;
@flowerinthenight
flowerinthenight / apc_as_fifo_queue.cpp
Last active July 8, 2019 08:24
Using thread APC as FIFO queue to avoid using explicit locking/synchronization when enqueueing/dequeueing.
#include <Windows.h>
typedef struct _param_t {
int code;
} param_t;
HANDLE hTerm = NULL; // terminate event
HANDLE hThr = NULL; // apc thread
HANDLE hReady = NULL; // apc thread ready event