Skip to content

Instantly share code, notes, and snippets.

View piaoger's full-sized avatar

Piaoger piaoger

View GitHub Profile
@piaoger
piaoger / install-valkan-library.sh
Created March 8, 2019 09:29
install libvulkan in Ubuntu
##https://vulkan.lunarg.com/
## https://vulkan.lunarg.com/sdk/home
# 18.04
wget -qO - http://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-1.1.101-bionic.list http://packages.lunarg.com/vulkan/1.1.101/lunarg-vulkan-1.1.101-bionic.list
sudo apt update
sudo apt install lunarg-vulkan-sdk
@piaoger
piaoger / filetime.go
Last active May 11, 2017 03:41
get/set filetime in golang
import (
"os"
"syscall"
"time"
)
func statTimes(name string) (atime, mtime, ctime time.Time, err error) {
fi, err := os.Stat(name)
if err != nil {
@piaoger
piaoger / json_toml_marshal_unmarshal.go
Last active April 17, 2017 08:07
marshal and unmarshal of json/toml
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/BurntSushi/toml"
"errors"
)
// borrowed from golang playgroud:
@piaoger
piaoger / kill-processes.sh
Last active November 23, 2016 07:02
kill processes by name
#!/bin/bash
appname=python
getpids() {
local pids=$(ps -ef | grep $1 | grep -v grep| awk '{print $2}')
echo $pids
}
pids=`getpids $appname`
@piaoger
piaoger / linux-date-handling.sh
Last active November 13, 2016 13:13
handling date in linux bash
# I want compress yesterday's log, so I have to learn how to get yesterday with bash
# yesterday=$(date --date='-1 day' +%Y-%m-%d)
# today=$(date +%Y-%m-%d)
# yesterday_log=service_log_${yesterday}.log
# zip ${yesterday_log}.zip ${yesterday_log}
## today
today=$(date +%Y-%m-%d)
@piaoger
piaoger / raii-resource-management.txt
Last active October 18, 2016 03:48
raii style resource management
# raii (c++)
before:
void UseFile(char const* fn)
{
FILE* f = fopen(fn, "r"); // 获取资源
// 使用资源
try {
if (!g()) { fclose(f); return; }
// ...
@piaoger
piaoger / memory-unsafty.c
Last active October 18, 2016 03:58
memory unsafe in c
// https://en.wikipedia.org/wiki/Dangling_pointer
void f() {
int *x = malloc(sizeof(int));
*x = 1024;
printf("%d\n", *x);
@piaoger
piaoger / rust-intro-borrow.rs
Last active October 17, 2016 09:53
rust-intro: borrow
// http://rustbyexample.com/scope/borrow.html
// https://is.gd/E0jeLL
fn simple_borrow() {
let mut v = vec!["A"];
{
// immutable borrow
@piaoger
piaoger / rust-intro-helloworld.rs
Last active October 18, 2016 06:50
rust-into: hello
// https://play.rust-lang.org/
// https://is.gd/VHQlvO
// Line comments which go to the end of the line.
/* Block comments which go to the closing delimiter. */
fn main () {
@piaoger
piaoger / open-current-dir.sh
Created September 29, 2016 03:37
open file manager of current directory in the terminal
# open file manager of current directory in the terminal
# http://askubuntu.com/questions/31069/how-to-open-a-file-manager-of-the-current-directory-in-the-terminal
xdg-open .
# mac
# open .