Skip to content

Instantly share code, notes, and snippets.

@uhziel
uhziel / demo_urllib.py
Created November 7, 2010 13:56
use a urllib library
import urllib
webpage = urllib.urlopen('http://www.baidu.com')
pagefile = open('baidu.html', 'w')
for lines in webpage.readlines():
pagefile.write(lines)
pagefile.close()
webpage.close()
@uhziel
uhziel / apue.2e.fig1.3.c
Created September 25, 2011 16:23
apue.2e.fig1.3.c
#include "apue.h"
#include <dirent.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
{
@uhziel
uhziel / apue.2e.fig1.4.c
Created September 25, 2011 16:27
apue.2e.fig1.4.c
#include "apue.h"
#define BUFFSIZE 4096
int main()
{
int n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
@uhziel
uhziel / apue.2e.fig1.5.c
Created September 25, 2011 16:34
apue.2e.fig1.5.c
#include "apue.h"
int main()
{
int c;
while ((c = getc(stdin)) != EOF)
{
if (putc(c, stdout) == EOF)
{
@uhziel
uhziel / apue.2e.fig1.6.c
Created September 26, 2011 16:28
apue.2e.fig1.6.c
#include "apue.h"
int main()
{
printf("hello world from process ID %d\n", getpid());
return 0;
}
@uhziel
uhziel / apue.2e.fig1.7.c
Created September 26, 2011 17:46
apue.2e.fig1.7.c
#include "apue.h"
#include <sys/wait.h>
int main()
{
char buf[MAXLINE];
pid_t pid;
int status;
printf("%% ");
@uhziel
uhziel / apue.2e.fig1.8.c
Created September 30, 2011 14:08
apue.2e.fig1.8.c
#include "apue.h"
#include <errno.h>
int main(int argc, char *argv[])
{
errno = E2BIG;
printf("E2BIG: %s", strerror(errno));
errno = EAGAIN;
perror(argv[0]);
return 0;
@uhziel
uhziel / apue.2e.fig1.9.c
Created September 30, 2011 14:11
apue.2e.fig1.9.c
#include "apue.h"
int main()
{
printf("uid = %d, gid = %d\n", getuid(), getgid());
return 0;
}
@uhziel
uhziel / apue.2e.fig1.10.c
Created September 30, 2011 15:09
apue.2e.fig1.10.c
#include "apue.h"
#include <sys/wait.h>
static void sig_int(int signo);
int main()
{
char buf[MAXLINE];
pid_t pid;
int status;
@uhziel
uhziel / apue.2e.fig3.1.c
Created October 15, 2011 01:55
apue.2e.fig3.1.c
#include "apue.h"
int main()
{
if (lseek(STDIN_FILENO, 0, SEEK_CUR == -1))
{
printf("cannot seek\n");
}
else
{