Skip to content

Instantly share code, notes, and snippets.

@styxyang
styxyang / string_copy.c
Created September 21, 2021 16:32
secure string copy test
#include <stdio.h>
#include <string.h>
#include <securec.h>
#define HELLOWORLD "helloworld"
#define HELLOWORLD1 "helloworld1"
int main()
{
char name[sizeof(HELLOWORLD)] = HELLOWORLD;
char name1[sizeof(HELLOWORLD1)] = HELLOWORLD1;

原文

新老用户都可能遇到陷阱。下面我们列出频繁出现的问题,以及如何解决。 在 Freenode IRC #nginx 频道,我们经常看到这些问题。

[TOC]

关于本指南

最常见的是有人试图从其他指南拷贝配置片段。并非所有的指南是错误的,但绝大部分是有问题的。

Testing of Xen vPMU filter options.

Three tests are executed on a simple program (noploop, which runs NOP in a loop). The first two show Linux "perf stat" summaries, and the third tests specific counters: the IPC ones, an architectural one, and a few extras. Which of these will work depends on the filter mode.

I'll begin by showing off and on, the current modes, and then the new modes: ipc and arch.

vpmu=off (default)

root@lgud-bgregg:~> xl dmesg | grep vpmu
package main
import (
"errors"
"log"
"runtime"
"sync/atomic"
"time"
)
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
@styxyang
styxyang / numlock_osx.xml
Last active July 26, 2022 03:36
This is a Karabiner configuration to get NumLock work on OS X the same way as PC
<!-- Get NumLock on keypad to work on osx for G80-3494, Realforce and so on -->
<!-- By https://groups.google.com/d/msg/osx-karabiner/-2ns5XVXXdQ/kDGIKVSztjwJ -->
<item>
<name>Map NumLock to OSX NumLock function</name>
<identifier>private.pc_numlock_to_mac_numlock</identifier>
<autogen>__KeyToKey__ KeyCode::KEYPAD_CLEAR, KeyCode::VK_IOHIKEYBOARD_TOGGLE_NUMLOCK</autogen>
</item>
@styxyang
styxyang / grade-breakpoint.tcl
Created October 22, 2013 08:49
tcl script to test gdb-like breakpoint function for jos lab
#!/usr/bin/expect -f
set timeout 10; # set timeout to -1 to wait forever
set hda "obj/kern/kernel.img"
# spawn qemu -nographic -hda $hda -serial "file:jos.out" -monitor null -no-reboot
spawn qemu -nographic -hda $hda -monitor null -no-reboot
# interact
expect {

On naming and cache

There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton

On reusing code

There are two "rules of three" in [software] reuse:

a. It is three times as difficult to build reusable components as single use components, and
b. a reusable component should be tried out in three different applications before it will be sufficiently general to accept into a reuse library.

@styxyang
styxyang / proc-port.sh
Last active December 20, 2015 00:49
find out which process has the connection on one port
# `sudo' is needed on Debian
lsof -n -i4TCP:7777
@styxyang
styxyang / randstr.sh
Created July 18, 2013 05:33
I tried my best to use one-line perl script to reach this... But I actually want to achieve the effects in comments, though failed.
perl -e '@r = ("A".."Z", 0..9); foreach (1..shift) { print join "", @r[ map { rand @r } 1..16 ], "\n" }' -- 8
# perl -e 'print join "", ("A".."Z")[ map { rand @("A".."Z") } 1..shift ], "\n"' -- 16