Skip to content

Instantly share code, notes, and snippets.

@tom-code
tom-code / tapdev.cc
Last active September 21, 2017 18:27
minimal code to create tap device
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <arpa/inet.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/socket.h>
https://www.kernel.org/doc/Documentation/vfio.txt
root@sax13 ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens2f0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 38:ea:a7:35:58:e0 brd ff:ff:ff:ff:ff:ff
3: ens2f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 38:ea:a7:35:58:e1 brd ff:ff:ff:ff:ff:ff
4: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether fc:15:b4:0d:62:60 brd ff:ff:ff:ff:ff:ff
cat .gtkrc-2.0
include "/root/.gtkrc-2.0.mine"
gtk-theme-name="Adwaita"
gtk-icon-theme-name="Adwaita"
gtk-font-name="MiscFixedSC613 9"
gtk-cursor-theme-size=0
gtk-toolbar-style=GTK_TOOLBAR_BOTH
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
gtk-button-images=1
@tom-code
tom-code / cload.java
Last active September 22, 2017 00:45
classloader - two jars with different versions of same classes
public class Main {
public static void main(String[] args) {
Main m = new Main();
TestClassIface t1 = m.load("test/1.jar");
TestClassIface t2 = m.load("test/2.jar");
t1.execute();
t2.execute();
}
TestClassIface load(String path) {
try {
@tom-code
tom-code / jarload.java
Created September 22, 2017 00:41
instantiate classes from jar based on annotation
public class Main {
public static void main(String[] args) {
load("test/1.jar");
load("test/2.jar");
}
private static void load(String path) {
try {
ClassLoader cl = new URLClassLoader(new URL[] { new File(path).toURL()});
@tom-code
tom-code / ocaelf.ml
Last active October 3, 2017 23:56
temp
type section = {
idx : int;
link : int;
mutable name : string;
offset : int;
name_offset : int;
entsize : int
};;
@tom-code
tom-code / editqcow.sh
Created October 13, 2017 19:39
edit qcow
qemu-nbd --connect=/dev/nbd1 CentOS-7-x86_64-GenericCloud.qcow2
mount /dev/nbd1p1 /mnt/
sed -i -e 's/root:!!:/root::/g' /mnt/etc/shadow
rm /mnt/etc/sysconfig/network-scripts/ifcfg-eth0
umount /mnt/
qemu-nbd -d /dev/nbd1
@tom-code
tom-code / create.sh
Created October 13, 2017 19:42
create openstack configdrive for cloud-init
truncate -s 1M cloudconfig.img
/usr/sbin/mkfs.vfat -n config-2 cloudconfig.img
mmd -i cloudconfig.img ::openstack
mmd -i cloudconfig.img ::openstack/latest
mcopy -i cloudconfig.img meta_data.json network_data.json ::openstack/latest
@tom-code
tom-code / avrdec.java
Created October 27, 2017 16:33
decode avro data (java/generic)
//avro-tools.jar needed
Schema schema = new Schema.Parser().parse(new File("/data/work/avro/message.avro"));
DatumReader<GenericRecord> dr = new GenericDatumReader<GenericRecord>(schema);
InputStream in = new FileInputStream(new File("/data/work/avro/record_pack/record_1_202571858.bin"));
BinaryDecoder decoder= DecoderFactory.get().binaryDecoder(in, null);
GenericRecord out = dr.read(null, decoder);
System.out.println(out);
@tom-code
tom-code / netconf.java
Created December 15, 2017 09:16
netconf client java miniexample
package org.tom;
import com.tailf.jnc.*;
import java.io.IOException;
public class Main {
static void dumpNode(Element e, String pad) {
Element n = e.getChild("name");
if (n != null) {