This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
void redirect_to(char *filename) | |
{ | |
int fd = open(filename, O_RDWR | O_CREAT, 0666); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
trap "echo TRAP!!; exit" SIGTERM SIGINT SIGHUP | |
for (( i=0; i<5; i=i+1 )) | |
do | |
echo $i | |
sleep 1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- encoding: utf8 | |
# sudo easy_install PIL | |
import Image | |
import ImageFont | |
import ImageDraw | |
import sys | |
import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use strace and ltrace to trace the runtime behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import os | |
for t in range(60)*100: | |
for i in range(1,10,2)+range(7,0,-2): | |
print ' '*t+'\033[1;5;3'+str(t%5+1)+';4'+str(t%5+1)+'m'+'*'*i+'\033[m' | |
time.sleep(0.1) | |
os.system('clear') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = range(100) | |
result = set(num) | |
for i in range(2,10): | |
result -= set(num[i*2::i]) | |
result -= set([0,1]) | |
print result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyClass | |
{ | |
public function __construct() | |
{ | |
} | |
public function __call($name, $args) | |
{ | |
echo "You called method \"$name\", and the args is:\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
本範例使用 PHPMailer (http://sourceforge.net/projects/phpmailer/) 發送 email。 | |
首先需要注意的是,下載時有可能讓人困惑,我下載的是 http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/ 這個版本。 | |
執行方式:使用 command line php 直接執行 `$ php ezgmail.php` | |
範例中包含設定方式、訊息樣板 (msg)、簡單樣板引擎 (fill_template)、名單的 parser (parse_name_list_tsv)與自動根據名單發信的範例,皆相當容易修改。 | |
需注意的是,Gmail 有發送郵件相關的限制,若超過限制,帳號會被暫時停用一天。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <set> | |
using namespace std; | |
class MyClass{ | |
public: | |
MyClass (int _x, int _y):x(_x),y(_y){} | |
bool operator<(const MyClass& rhs) const { | |
return this->x < rhs.x ? true : (this->y < rhs.y ? true : false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
infile = sys.argv[1] | |
outfile = sys.argv[2] | |
key = bytearray(sys.argv[3].decode('hex')) | |
b = bytearray(open(infile, 'rb').read()) | |
i = 0 |