Skip to content

Instantly share code, notes, and snippets.

@datar
datar / gist:70ccce623177a2b05717801ba4b7ab13
Created December 27, 2017 01:36 — forked from tobert/gist:8063382
Switching clock from TSC to HPET on Linux.
tobert@spaceghost /sys/devices/system/clocksource/clocksource0 $ cat /proc/cpuinfo |grep 'model name' |head -n 1
model name : Intel(R) Xeon(R) CPU E31270 @ 3.40GHz
tobert@spaceghost /sys/devices/system/clocksource/clocksource0 $ cat /proc/version
Linux version 3.11.4-gentoo (root@sysresccd) (gcc version 4.6.4 (Funtoo 4.6.4) ) #1 SMP Mon Oct 7 05:33:55
tobert@spaceghost /sys/devices/system/clocksource/clocksource0 $ cat available_clocksource
tsc hpet acpi_pm
tobert@spaceghost /sys/devices/system/clocksource/clocksource0 $ cat current_clocksource
tsc
tobert@spaceghost /sys/devices/system/clocksource/clocksource0 $ echo hpet |sudo tee current_clocksource
hpet
url = 'https://www.zhihu.com/people/fan-hai-wai-yao-yan/pins/posts'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.90 Safari/537.36'}
r = requests.get(url, headers=headers)
document = lxml.html.fromstring(r.text)
data = document.get_element_by_id('data')
content = json.loads(html.unescape(data.get('data-state')))
pattern = '<html lang="zh"><head data-reactid="2"><meta charset="utf-8" data-reactid="3"/><body>%s</body></html>'
@datar
datar / C-states.md
Created April 14, 2017 22:48 — forked from wmealing/C-states.md
What are CPU "C-states" and how to disable them if needed?

To limit a CPU to a certain C-state, you can pass the processor.max_cstate=X option in the kernel line of /boot/grub/grub.conf.

Here we limit the system to only C-State 1:

    kernel /vmlinuz-2.6.18-371.1.2.el5 ... processor.max_cstate=1

On some systems, the kernel can override the BIOS setting, and the parameter intel_idle.max_cstate=0 may be required to ensure sleep states are not entered:

@datar
datar / install-gcc48-linuxbrew-centos6.md
Created March 24, 2017 17:27 — forked from stephenturner/install-gcc48-linuxbrew-centos6.md
Installing gcc 4.8 and Linuxbrew on CentOS 6

Installing gcc 4.8 and Linuxbrew on CentOS 6

The GCC distributed with CentOS 6 is 4.4.7, which is pretty outdated. I'd like to use gcc 4.8+. Also, when trying to install Linuxbrew you run into a dependency loop where Homebrew's gcc depends on zlib, which depends on gcc. Here's how I solved the problem.

Note: Requires sudo privileges.

Resources:

@datar
datar / c11-w.sublime
Created July 11, 2016 04:48 — forked from qwo/c11-w.sublime
Sublime C++11 Build System File
//ignore being compatible with C++99 and other warnings
{
"cmd": ["clang++","-std=c++11", "-w", "-stdlib=libc++", "-Weverything", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
@datar
datar / http_server_by_python.txt
Created March 1, 2016 01:30
HTTP server by using python only
[HTTP server by using Python only](http://coolshell.cn/articles/1480.html)
如果你急需一个简单的Web Server,但你又不想去下载并安装那些复杂的HTTP服务程序,比如:Apache,ISS等。那么, Python 可能帮助你。使用Python可以完成一个简单的内建 HTTP 服务器。于是,你可以把你的目录和文件都以HTTP的方式展示出来。佻只需要干一件事情,那就是安装一个Python。
实际上来说,这是一个可以用来共享文件的非常有用的方式。实现一个微型的HTTP服务程序来说是很简单的事情,在Python下,只需要一个命令行。下面是这个命令行:(假设我们需要共享我们的目录 /home/haoel 而IP地址是192.168.1.1)
1
2
$ cd /home/haoel
$ python -m SimpleHTTPServer
/*
* Copyright 2014 Google Inc.
* Author: willemb@google.com (Willem de Bruijn)
*
* Test software tx timestamping, including
*
* - SCHED, SND and ACK timestamps
* - RAW, UDP and TCP
* - IPv4 and IPv6
* - various packet sizes (to test GSO and TSO)
// avoid error::bind address already in use
// set socket can be reuse
int on = 1;
setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) );
/*
* This program demonstrates how the various time stamping features in
* the Linux kernel work. It emulates the behavior of a PTP
* implementation in stand-alone master mode by sending PTPv1 Sync
* multicasts once every second. It looks for similar packets, but
* beyond that doesn't actually implement PTP.
*
* Outgoing packets are time stamped with SO_TIMESTAMPING with or
* without hardware support.
*
@datar
datar / gist:917efee52e4631cb2368
Last active August 29, 2015 14:17
use xlrd to load data from xls or xlsx file
import xlrd
def main():
datafile = xlrd.open_workbook('datafile.xls')
sheet_names = datafile.sheet_names()
for sheet_name in sheet_names:
sheet = datafile.sheet_by_name(sheet_name)
sheet.col_values(col_index, row_index_begin, row_index_end)
if __name__ == '__main__':