卖萌的弱渣

I am stupid, I am hungry.

Anagrams

Anagrams

Given an array of strings, return all groups of strings that are anagrams.

Example

Given [“lint”, “intl”, “inlt”, “code”], return [“lint”, “inlt”, “intl”].

Given [“ab”, “ba”, “cd”, “dc”, “e”], return [“ab”, “ba”, “cd”, “dc”].

Note

All inputs will be in lower-case

Dump Stack in Linux

dump_stack() is a useful tool to understand call procedure of a function. You can enable it in the kernel source.

Enable dump_stack

Make sure the following flag is y

  • CONFIG_PREEMPT
  • CONFIG_DEBUG_KERNEL
  • CONFIG_KALLSYMS
  • CONFIG_SPINLOCK_SLEEP
  • CONFIG_MAGIC_SYSRQ

Use dump_stack in your code

1
2
printk(KERN_ERR, "%x", parameter);
dump_stack()

After that

You can watch the stack result in dmesg

How to Write a Service Script

Script location

/etc/init.d

Header

xxx is the script name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh
#
# /etc/init.d/xxx
# Subsystem file for "xxx" server
# 
#
# chkconfig: 2345 95 05
# description: xxx server daemon
# 
# processname: xxx
# config: /etc/xxx/xxx.conf      // Config file
# config: /etc/sysconfig/xxx     // config file
# pidfile: /var/run/xxx.pid

### BEGIN INIT INFO
# Provides: xxx
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon
### END INIT INFO

Compile One Specific Kernel Module Without Clean All Kernel Sources

1
cd kernel soruce dir
1
2
# make sure CONFIG_FB_UVESA can be found in Kconfig
make M=drivers/video/ CONFIG_FB_UVESA=m

If you dont have CONFIG_FB_UVESA or similar

1
make drivers/video/uvesafb.ko

The loadable modules are located in

1
/lib/modules/kernel-version/kernel/driver

Python: Standard Library II

Output Formatting

  • reprlib can provide abbreviated displays of large containers
1
2
3
>>> import reprlib
>>> reprlib.repr(set('supercalifragi'))
"{'a','c','d','e','f','g',...}"
  • pprint offer more sophisticated control over built-in and user-defined objects.
1
2
3
4
5
6
7
8
9
10
>>> import pprint
>>> t = [[[['black', 'cyan'], 'white', ['green', 'red']], [['magenta',
...     'yellow'], 'blue']]]
...
>>> pprint.pprint(t, width=30)
[[[['black', 'cyan'],
   'white',
   ['green', 'red']],
  [['magenta', 'yellow'],
   'blue']]]
  • textwrap can format paragraphs of text to fit a given screen width
1
2
3
4
5
6
7
8
9
10
>>> import textwrap
>>> doc = """The wrap() method is just like fill() except that it returns
... a list of strings instead of one big string with newlines to separate
... the wrapped lines."""
...
>>> print(textwrap.fill(doc, width=40))
The wrap() method is just like fill()
except that it returns a list of strings
instead of one big string with newlines
to separate the wrapped lines.

Python: Standard Library

Operating System Interface

The os module provides dozens of functions to interact wieh OS.

1
2
3
4
5
6
>>> import os
>>> os.getcwd()                     # Return current working directory
'C:\\Python35'
>>> os.chdir('/server/accesslogs')  # Change current working directory
>>> os.system('mkdir today')        # Run the command "mkdir" in system shell
0

Be usre to use import os rather than from os import *

  • The built-in dir() and help() functions are useful.
1
2
>>> dir(os)   # return all module functions
>>> help(os)  # return manual page.
  • The shutil can provide higher level interface
1
2
3
4
5
>>> shutil.copyfile('data.db', 'archive.db')
'archive.db'

>>> shutil.move('/build/executables', 'installdir')
'installdir'

QEMU-KVM Install Guest VM

Create a qcow2 disk image

1
qemu-img create -f qcow2 ./win7.img 10G

Install OS on the new image

1
qemu-system-xxx -hda win7.img -boot d -cdrom ./instal-image.iso -m 512

Boot after install

1
qemu-system-xxx -hda win7.img -m 512

The above instructions only use most basic options to make it happen

Make OSX Installer (Iso) by Using Install App

  • so let’s start with that:
1
sudo -s
  • Mount the installer image:
1
hdiutil attach /Applications/Install\ OS\ X\ Yosemite.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
  • Convert the boot image to a sparse bundle:
1
hdiutil convert /Volumes/install_app/BaseSystem.dmg -format UDSP -o /tmp/Yosemite