Skip to content

Instantly share code, notes, and snippets.

View dapangmao's full-sized avatar
🏠
Working from home

Dapangmao dapangmao

🏠
Working from home
View GitHub Profile
#!/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
@dapangmao
dapangmao / gist:b0ba14b7dcfc83d152e5
Last active August 29, 2015 14:04
add comment to py
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)
@dapangmao
dapangmao / gist:1e9301dd28b6b2a96cae
Last active August 29, 2015 14:05
zz from mitbbs
# 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).
@dapangmao
dapangmao / gist:1b3a24aba155bb8fb022
Last active August 29, 2015 14:05
String and mathematics
#-------------------------------------------------------------------------------
# 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:
@dapangmao
dapangmao / Linkedlist.md
Last active June 15, 2021 17:56
Linked List
  • 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):
@dapangmao
dapangmao / tree.md
Last active August 29, 2015 14:05
Trees
  • The class to create tree
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]
@dapangmao
dapangmao / _1search.md
Last active August 29, 2015 14:05
Search and others
  • Recursive method
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:
@dapangmao
dapangmao / TDD.py
Last active August 29, 2015 14:06
TDD in Python
"""Convert to and from Roman numerals"""
#-------------------------------------------------------------------------------
#
# http://woodpecker.org.cn/diveintopython/unit_testing/stage_1.html
#
#-------------------------------------------------------------------------------
import re