Skip to content

Instantly share code, notes, and snippets.

View huwan's full-sized avatar

Hu Wan huwan

  • City University of Hong Kong
  • 17:45 (UTC +08:00)
View GitHub Profile
@phaustin
phaustin / 00README.rst
Created February 17, 2013 22:17 — forked from GaelVaroquaux/00README.rst
passing arrays to cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

@rjzak
rjzak / PyUtils.cpp
Last active May 15, 2024 21:06
Convert between Python list/tuples and C++ vectors
#include <Python.h> // Must be first
#include <vector>
#include <stdexcept>
#include "PyUtils.h"
using namespace std;
// =====
// LISTS
// =====
@ork
ork / Makefile
Last active January 8, 2022 17:29
Generic C Makefile
EXEC = $(shell basename $$(pwd))
CC = gcc
CFLAGS = -std=gnu11 -O3 -Wall -Wextra -Wpedantic -Wstrict-aliasing
CFLAGS += $(shell pkg-config --cflags glib-2.0 gio-2.0)
LDFLAGS = $(shell pkg-config --libs glib-2.0 gio-2.0)
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
@huwan
huwan / README.md
Last active August 29, 2015 14:02
Linux 定时使用脚本检测程序运行状态并通过飞信进行通知

Linux 定时使用脚本检测程序运行状态并通过飞信进行通知

  • 可以通过输入进程号(精确匹配)(注)或者特定的进程名称(模糊匹配)
  • 当程序完成退出后,通过中国移动[命令行飞信] 1 进行提醒
  • 需结合crontab 计划任务服务,每隔10分钟执行一次检测任务

注:因为是使用ps -ef + grep 所以,有可能一个进程号在多列出现,并不是完全意义上的精确匹配,但实际使用中一般不会出问题,可以先人工确认一下是否唯一

@Enucatl
Enucatl / weighted.mean.sh
Created October 27, 2014 13:31
calculate weighted average with first column = value, second column = weight with awk
#!/usr/bin/env bash
awk '{w = w + $2; e = e + $1 * $2;} END {print e/w}'
#!/bin/sh
# $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $
# Convert PDF to encapsulated PostScript.
# usage:
# pdf2eps <page number> <pdf file without ext>
pdfcrop $2.pdf
pdftops -f $1 -l $1 -eps "$2-crop.pdf"
rm "$2-crop.pdf"
mv "$2-crop.eps" $2.eps
@jvenator
jvenator / gist:9672772a631c117da151
Last active April 25, 2025 17:44
PDFtk Server Install Workaround for Mac OS X

Installing PDFtk Server edittion on your Mac

This workaround install is necessary because PDFtk was pulled from homebrew-cask due to issues with it aggressively overwriting file permissions that could impact other installed libraries. See this homebrew-cask issue.
The following steps worked on Mac OS X 10.10.1 with a standard brew installation for the PDFtk Mac OS X server libary version 2.02.
All Terminal commands separated by a full line space. Some commands wrap into multiple lines.

Download and extract the Mac OS X server install pacakge

@tenomoto
tenomoto / pdf2eps
Created April 28, 2015 07:59
Create EPS from PDF with white margin cropped using pdfcrop and pdftoeps
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Usage :: $0 input.pdf [p1 p2 ...]"
exit
fi
in=${1}
shift
pdfcrop ${in}
crop=`basename -s .pdf ${in}`-crop
if [ $# -eq 0 ]; then
@protrolium
protrolium / ffmpeg.md
Last active April 27, 2025 21:52
ffmpeg guide

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

You can get the list of installed codecs with:

@beci
beci / gcc 5 on ubuntu 14.04
Created October 15, 2015 07:18
use gcc 5.x on ubuntu 14.04
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5 g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5