Skip to content

Instantly share code, notes, and snippets.

@diabloneo
diabloneo / timespec_diff.c
Created March 18, 2014 13:22
Calculate diff of two struct timespec
#include <time.h>
void timespec_diff(struct timespec *start, struct timespec *stop,
struct timespec *result)
{
if ((stop->tv_nsec - start->tv_nsec) < 0) {
result->tv_sec = stop->tv_sec - start->tv_sec - 1;
result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000;
} else {
result->tv_sec = stop->tv_sec - start->tv_sec;
@diabloneo
diabloneo / README.md
Created February 23, 2022 11:45
Build kernel-ark 5.15 with mock config centos-stream+epel8-x86_64 failed

I tried to build kernel 5.15 for Rocky Linux 8 with mock. But I failed on tools/iio

The error is gcc can not find the correct headers:

~/build/BUILD/kernel-5.15.19-0.test/linux-5.15.19-0.test.el8.x86_64
~/build/BUILD/kernel-5.15.19-0.test/linux-5.15.19-0.test.el8.x86_64/tools/iio ~/build/BUILD/kernel-5.15.19-0.test/linux-5.15.19-0.test.el8.x86_64
+ popd
+ pushd tools/iio/
+ /usr/bin/make -s 'HOSTCFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'HOSTLDFLAGS=-Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' 'CFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redha
@diabloneo
diabloneo / fill_struct_string.go
Last active March 25, 2021 06:31
Fill a Golang struct's string fields' values according with fieldss names.
package common
import (
"fmt"
"go/token"
"reflect"
)
// FillStructString set values of string fields of a struct to the field names.
func FillStructString(value interface{}) {
@diabloneo
diabloneo / jekyll-and-liquid.md
Created April 16, 2018 15:34 — forked from magicznyleszek/jekyll-and-liquid.md
Jekyll & Liquid Cheatsheet

Jekyll & Liquid Cheatsheet

A list of the most common functionalities in Jekyll (Liquid). You can use Jekyll with GitHub Pages, just make sure you are using the proper version.

Running

Running a local server for testing purposes:

@diabloneo
diabloneo / main.go
Last active December 9, 2016 07:31
Set array element of a JSON using go-simplejson
package main
import (
"fmt"
"github.com/bitly/go-simplejson"
)
func testJsonArray1(pgStatsJson []*simplejson.Json) {
fmt.Println("testJsonArray1")
j := simplejson.New()
@diabloneo
diabloneo / main.go
Created January 19, 2016 04:03
Execute command with timeout
package main
import (
"fmt"
"os/exec"
"time"
)
func main() {
cmd := exec.Command("./pause1min")
@diabloneo
diabloneo / rds_authenticator.py
Created September 2, 2013 11:35
Calculate RADIUS packet authenticator. Input packet's hex string, output authenticator in hex form.
#!/usr/bin/env python
import hashlib
import base64
import binascii
def main():
pktstr = raw_input()
m = hashlib.md5()
m.update(base64.b16decode(pktstr.replace(' ', '').upper()))
@diabloneo
diabloneo / tmux_start.sh
Created November 27, 2012 13:37
Starting tmux with specific windows
#!/bin/bash
ROOTDIR=~/ruijie
SESSION=main
NONAME="bash"
window_list="tftp $NONAME ipython $NONAME"
tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
echo "Session $SESSION already exists. Attacing."
@diabloneo
diabloneo / 99
Created March 26, 2015 01:48
九九乘法表
[[y*x for x in range(1, y+1)] for y in range(1, 10)]
@diabloneo
diabloneo / queen.py
Created March 7, 2015 09:21
N Queens Problem -- in recursive method
#!/usr/bin/env python
# -*- coding: utf-8 -*-
count = 0
def can_place(board, n, row, col):
if any([board[i][col] for i in range(row)]
+ [board[row-i][col-i] for i in range(1, row+1) if col >= i]
+ [board[row-i][col+i] for i in range(1, row+1) if (col+i) < n]):