- Transform list to linked list
class ListNode:
def __init__(self, val=None):
self.val = val
self.next = None
self.size = 0
if val:
self.size = 1
def add_to_last(self, x):
#!/bin/bash | |
# Check hardwares | |
cat /etc/redhat-release /proc/cpuinfo /proc/meminfo | |
df -h | |
# Install git | |
yum -y update | |
yum -y install git-core |
find ~ -mtime -1 -exec ls -l {} \; |
#------------------------------------------------------------------------------- | |
# Name: sas2sqlite | |
# Purpose: translate a SAS data set to a SQLite table | |
# | |
#------------------------------------------------------------------------------- | |
def sas2sqlite(sasfile, sqlitedb): | |
import sqlite3 | |
from sas7bdat import SAS7BDAT | |
# Read data from SAS |
import sys | |
if len(sys.argv) < 3: | |
sys.exit("Must have infile and outfile") | |
with file(sys.argv[1], 'r+') as infile, file(sys.argv[2], 'w+') as outfile: | |
for x in infile: | |
outfile.write('* ' + x) |
# Create a new tar archive. | |
# the folder dirname/ is compressed into archive_name.tar | |
tar cvf archive_name.tar dirname/ | |
# Extract from an existing tar archive | |
tar xvf archive_name.tar | |
# View an existing tar archive | |
tar tvf archive_name.tar | |
# Search for a given string in a file (case in-sensitive search). |
#------------------------------------------------------------------------------- | |
# Name: Sort Color | |
# Purpose: | |
# | |
# Given an array with n objects colored red, white or blue, sort them so that objects | |
# of the same color are adjacent, with the colors in the order red, white and blue. | |
# | |
# Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. | |
# | |
# Note: |
class ListNode:
def __init__(self, val=None):
self.val = val
self.next = None
self.size = 0
if val:
self.size = 1
def add_to_last(self, x):
class TreeNode:
def __init__(self, val):
self.left = None
self.right = None
self.val = val
def to_root(input):
a = [TreeNode(i) if i != '#' else None for i in input]
def binary_search(A, target):
return _binary_search(A, target, 0, len(A) - 1)
def _binary_search(A, target, lo, hi):
if lo > hi:
return -1
mid = (lo + hi) / 2
if A[mid] == target:
"""Convert to and from Roman numerals""" | |
#------------------------------------------------------------------------------- | |
# | |
# http://woodpecker.org.cn/diveintopython/unit_testing/stage_1.html | |
# | |
#------------------------------------------------------------------------------- | |
import re |