Skip to content

Instantly share code, notes, and snippets.

View xueliu's full-sized avatar
🏠
Working from home

Xue Liu xueliu

🏠
Working from home
View GitHub Profile
@xueliu
xueliu / function_signal_handler.cpp
Created May 2, 2018 14:26
using std::function to provide signal handler
#include <functional>
#include <iostream>
namespace {
std::function<void(int)> shutdown_handler;
void signal_handler(int signal) { shutdown_handler(signal); }
} // namespace
int main(int argc, char *argv[]) {
std::signal(SIGINT, signal_handler);
@xueliu
xueliu / termios_dbg.c
Created May 16, 2018 14:51 — forked from erichschroeter/termios_dbg.c
Debug statements for termios struct.
#include <stdio.h>
#include <sys/ioctl.h>
#include "termios_dbg.h"
#define CHECK_BIT(var, pos) ((var) & (1<<(pos)))
void ptermios_iflag(struct termios *tty)
{
printf("c_iflag=0x%x\n", tty->c_iflag);
@xueliu
xueliu / termios_dbg.c
Created May 16, 2018 14:51 — forked from erichschroeter/termios_dbg.c
Debug statements for termios struct.
#include <stdio.h>
#include <sys/ioctl.h>
#include "termios_dbg.h"
#define CHECK_BIT(var, pos) ((var) & (1<<(pos)))
void ptermios_iflag(struct termios *tty)
{
printf("c_iflag=0x%x\n", tty->c_iflag);
@xueliu
xueliu / construct_tag
Created February 1, 2019 09:51
make_shared (and make_unique) for classes with private constructors
class Test
{
private:
struct _constructor_tag { explicit _constructor_tag() = default; };
public:
Test(_constructor_tag) {}
static unique_ptr<Test> factory()
{
@xueliu
xueliu / circular.cpp
Last active January 2, 2022 14:36
STL风格的ring buffer实现
/******************************************************************************
* $Id: $
* $Name: $
*
* Author: Pete Goodliffe
*
* ----------------------------------------------------------------------------
* Copyright 2002 Pete Goodliffe All rights reserved.
*
* ----------------------------------------------------------------------------
#ifndef DELEGATE_HPP_INCLUDED
#define DELEGATE_HPP_INCLUDED
#include <functional>
#include <vector>
// general case
template<typename R, typename... Args>
class delegate
{
#ifndef _DELEGATE_H_
#define _DELEGATE_H_
/**
* non specialized template declaration for delegate
*/
template <typename T>
class delegate;
/**
Sat Jan 31 06:22:30 1970 kern.notice kernel: [ 0.000000] Linux version 4.4.14 (build@7e42c4b42298) (gcc version 5.3.0 (OpenWrt GCC 5.3.0 v1.1.0) ) #3 SMP Tue Feb 14 20:33:07 UTC 2017
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] SoC Type: IMG Pistachio SoC (B0)
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] bootconsole [early0] enabled
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] CPU0 revision is: 0001a120 (MIPS interAptiv (multi))
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] FPU revision is: 0173a000
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] MIPS: machine is IMG marduk - Creator Ci40 with ca8210
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] Determined physical RAM map:
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] memory: 10000000 @ 00000000 (usable)
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] Initrd not found or empty - disabling initrd
Sat Jan 31 06:22:30 1970 kern.info kernel: [ 0.000000] Zone ran
#!/bin/bash
echo "21" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio21/direction
echo "1" > /sys/class/gpio/gpio21/value
sleep 5
echo "0" > /sys/class/gpio/gpio21/value
sleep 1
echo "0" > /sys/class/gpio/gpio21/value
#!/bin/sh
qemu-system-arm \
-M vexpress-a9 -smp 1 \
-m 256 \
-kernel output/images/zImage \
-dtb output/images/vexpress-v2p-ca9.dtb \
-drive file=output/images/rootfs.ext2,if=sd,format=raw \
-append "console=ttyAMA0,115200 root=/dev/mmcblk0" \
-net nic,model=lan9118 \