Skip to content

Instantly share code, notes, and snippets.

View vtta's full-sized avatar
🎯
Focusing

vtta vtta

🎯
Focusing
  • The Chinese University of Hong Kong
  • Hong Kong
View GitHub Profile
@vtta
vtta / perf_raw_event_code.c
Last active May 16, 2022 08:14
gcc perf_raw_event_code.c -lpfm -o perf_raw_event_code
#include <err.h>
#include <inttypes.h>
#include <perfmon/pfmlib.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
errx(1, "Usage: %s EVENT...\n", argv[0]);
}
@vtta
vtta / pxml.py
Last active March 10, 2022 01:58
Pretty printing xml file in a more human-readable format
#!/usr/bin/env python3
from argparse import ArgumentParser
from rich import print
from xml.etree import ElementTree
# credit: https://stackoverflow.com/questions/2148119/how-to-convert-an-xml-string-to-a-dictionary
class XmlListConfig(list):
def __init__(self, aList):
for element in aList:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDAd81U54uxTa+6lg0eDsJzpEqAnPQqnt7yNweOYXg62N4prsmZKCyGTB5diE0J1hqN3tULT694ngni10I2rNMIppNf283XORKtoCyrh7SHg1ILWr95wurYE5nmMBPz7M9HVdLC+AyFwRbx8hrdZvJUS6QCP4E2kzMAahJfNxt0p+NSZlNauqxEZAWP3x7DZwPi8S/t9r6EyQIr2kDIsNtjC8B/ktVf66UOYAin9zWTBBNvqu3zEV+knvqX/B1mQAScm5KR9+QDkIaM4GrBM4fzmBLAGfHoBlNKNsDaIq2UrIfTna0NObpCyqiONFerecYbhOidZY0yOMeyLaZXbAPYoW0erZzmFnryK6DAvLhqDaZffC1Lw2l9b/6uCTMuJ1UI1BV7GcCrZ6qcm4nFHGghBB4YP+bq1/YwGwLctONumAIj6OIR6yFMRNeWZOFl67Z3Q0osps5bXOllJsvudWuWCRd1ftL/JdPr8sBqh04N4tkAAYib4SXTPuV0cgzkW6iS5CpDknKTVqPikcNXo0YNsb8gwSOF3zBH6xx4CDEjyv5fow3k+5Hom1+UgYAn83oI0r37Oom/rmd3KL9CCUEyHeibOHxtrWTUaPb2tWNWwUYQST3/KO59P3xXOKfa/CkMJDzJtclkQHoZJWKuSlbnHZ+AGb+UvNCuoXIf9OIJ/Q==
#! /usr/bin/python3
#
# BSD LICENSE
#
# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
@vtta
vtta / Memory.cpp
Last active October 9, 2020 16:25
#include "Memory.h"
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
#include "Node.h"
using namespace std;
int kmp(string const &s, string const &p) {
auto ns = s.size(), np = p.size();
if (np == 0) {
return 0;
}
if (ns < np || ns == 0) {
return -1;
}
vector<size_t> next(np);
http://tracker.trackerfix.com:80/announce
udp://9.rarbg.me:2770
udp://9.rarbg.to:2760
udp://public.popcorn-tracker.org:6969/announce
http://104.28.1.30:8080/announce
http://104.28.16.69/announce
http://107.150.14.110:6969/announce
http://109.121.134.121:1337/announce
http://114.55.113.60:6969/announce
http://125.227.35.196:6969/announce
@vtta
vtta / qemu-ifup.sh
Created August 17, 2019 07:37
network set up script for kholia/OSX-KVM, usage: ./qemu-ifup.sh tap0
#!/bin/bash
set -x
switch=br0
if [ -n "$1" ];then
ip tuntap add $1 mode tap
ip link set $1 up promisc on
# ip link set $switch up
sleep 0.5s
@vtta
vtta / pip-uninstall-recursively.sh
Created August 8, 2019 15:32
pip uninstall recursively
#!/bin/sh
# for dep in $(pip show somepackage | grep Requires | sed 's/Requires: //g; s/,//g') ; do pip uninstall -y $dep ; done
for dep in $(pip show "$1" | grep Requires | sed 's/Requires: //g; s/,//g') ; do
pip uninstall -y $dep
done
pip uninstall -y "$1"
@vtta
vtta / nqueens-genetic-algorithm.cpp
Created May 1, 2019 18:17
N-Queens problem implemented using genetic algorithm. Support up to 255 queens. Algorithm will converge in a few minutes at most.
#include <bits/stdc++.h>
using namespace std;
bool CONVERGED = false;
int const MUTATION_STEP = 1e2;
int const ROULETTE_SIZE = 1e3;
int const MAX_INTERATION = 1e5;
void init(vector<string>& status)