Skip to content

Instantly share code, notes, and snippets.

#include<stdio.h>
@caisan
caisan / gist:d398d0ec3c0349248874c055942b4403
Created June 26, 2017 02:44
epoll server code snippet
while (1) {
time = zv_find_timer();
debug("wait time = %d", time);
n = zv_epoll_wait(epfd, events, MAXEVENTS, time);
zv_handle_expire_timers();
log_info("loop n:%d\n",n);
for (i = 0; i < n; i++) {
zv_http_request_t *r = (zv_http_request_t *)events[i].data.ptr;
fd = r->fd;
log_info("fd:%d\n", fd);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@caisan
caisan / gist:efd158a059432d5e7618011a2edfbc5d
Created October 20, 2017 08:02
create replica_set mongoDB
#!/bin/bash
TENANT_NAME=
ADMIN_USERNAME=
ADMIN_PASSWORD=
REQUEST="{\"auth\": {\"tenantName\":\"$TENANT_NAME\", \"passwordCredentials\": {\"username\": \"$ADMIN_USERNAME\", \"password\": \"$ADMIN_PASSWORD\"}}}"
RAW_TOKEN=`curl -s -d "$REQUEST" -H "Content-type: application/json" "http://{KeyStone_IP_ADDR:Port}/v2.0/tokens"`
TOKEN=`echo $RAW_TOKEN | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"`
echo $TOKEN\
def build_model(width, num_channels):
width, height, n_len, n_class = width, 40, 7, len(chars)+ 1
rnn_size = 256
input_tensor = Input((width, 40, 3))
x = input_tensor
base_conv = 32
for i in range(3):
x = Conv2D(base_conv * (2 ** (i)), (3, 3))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
@caisan
caisan / rootfs_ubuntu_16.04_btrfs.md
Created January 10, 2020 08:21 — forked from niflostancu/rootfs_ubuntu_16.04_btrfs.md
Installing Ubuntu 16.04 on btrfs using debootstrap

Installing Ubuntu 16.04 with btrfs using debootstrap

Partition layout

First, create a GPT partition table.

  1. boot partition, label: EFI, flags: boot + ESP; size: 1GB, format to FAT32;
  2. root partition (label: root), must same size on all devices!
  3. swap partition.
fio -filename=/dev/vdb -direct=1 -iodepth 1 -thread -rw=read -ioengine=libaio -bs=16k -size=200G -numjobs=30 -runtime=2400 -group_reporting -name=mytest
@caisan
caisan / VFIO_nested.md
Created July 9, 2020 12:27 — forked from mcastelino/VFIO_nested.md
QEMU VFIO in Nested VM vIOMMU

How to use VFIO to assign a device to nested VM

  • Here the vfio-pci device is passed in into the L1 VM
  • The L1 VM is setup with kernel_irqchip=split
  • The L0 exposes a virtual IOMMU to the L1 VM
qemu-system-x86_64 \
    -machine q35,accel=kvm,kernel_irqchip=split \
    -enable-kvm \
// =====================================================================================
//
// Filename: qemu phyaddr section.c
//
// Description:
//
// Version: 1.0
// Created: 2020/07/29 20时18分30秒
// Revision: none
// Compiler: g++
@caisan
caisan / qemu-networking.md
Created October 6, 2020 08:50 — forked from extremecoders-re/qemu-networking.md
Setting up Qemu with a tap interface

Setting up Qemu with a tap interface

There are two parts to networking within QEMU:

  • The virtual network device that is provided to the guest (e.g. a PCI network card).
  • The network backend that interacts with the emulated NIC (e.g. puts packets onto the host's network).

Example: User mode network