Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
shaobin0604 / test_lf_cr.c
Created October 22, 2009 03:12
检测系统换行符
/*
============================================================================
Name : test_lf_cr.c
Author : shaobin0604
Version :
Copyright : Your copyright notice
Description : This small piece of code is used to detect the new line character
on different platforms.
eg.
@shaobin0604
shaobin0604 / progress_bar_in_console.rb
Created October 22, 2009 05:22
控制台生成进度条
#!/usr/bin/env ruby
#
# This script will generate a progress bar in console interface
#
0.upto(50) do |i|
printf("progress: [%-50s] %d%%\r", '#' * i, i * 2);
sleep(1)
end
#--------------------------------------------------
# Name: fullmetal_alchemist_comic_book_download_script.rb
# Description: This Ruby script is used to batch download Fullmetal Alchemis
# comic books which are hosted on http://www.jumpcn.com.
# Make ensure wget program can be found via PATH environment variable.
# The Windows version of wget program can be found at http://users.ugent.be/~bpuype/wget/.
#
# Usage:
# ruby fullmetal_alchemist_comic_book_download_script.rb chapter
#
@shaobin0604
shaobin0604 / queue_problem.rb
Created October 26, 2009 16:04
排队问题
# == Question:
# 12 people stand in two rows, 6 per row. People in each row must be
# arranged by their height and person in the second row must be taller
# than the one up front. Well, how many kinds of arrangement can be?
#
# == Solution:
# Suppose that person1 to person12 are marked by their height ascent
# We find the following rules:
# 1. Person at the first position of row 1 must be person1
# 2. Person at the second positon of row 1 must be in person2...person3, and person
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
int main(void)
{
int c, nl, nc, nw, state;
nl = nc = nw = 0;
state = OUT;
@shaobin0604
shaobin0604 / tcpl_ex-1-19.c
Created October 28, 2009 13:17
tcpl_ex-1-19.c
/*
* Exercise 1-19. Write a function reverse(s) that reverses the character
* string s. Use it to write a program that reverses its input a line at a time.
*
*/
#include <stdio.h>
#define MAXLINE 1000
void reverse(char line[]);
@shaobin0604
shaobin0604 / tcpl_ex-1-20.c
Created October 29, 2009 03:45
tcpl_ex-1-20.c
/*
* Exercise 1-20. Write a program detab that replaces tabs in the input
* with the proper number of blanks to space to the next tab stop. Assume
* a fixed set of tab stops, say every n columns. Should n be a variable
* or a symbolic parameter?
*/
#include <stdio.h>
#define MAXLEN 1000
@shaobin0604
shaobin0604 / tcpl_ex-1-21.c
Created October 29, 2009 08:47
tcpl_ex-1-21.c
/*
* Exercise 1-21. Write a program entab that replaces strings of blanks by the minimum
* number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab.
* When either a tab or a single blank would suffice to reach a tab stop, which should be given
* preference?
*/
#include <stdio.h>
#define TABINC 8
@shaobin0604
shaobin0604 / complete escape characters in ansi c
Created October 29, 2009 15:06
complete escape characters in ansi c
\a alert (bell) character
\b backspace
\f formfeed
\n newline
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\? question mark
\' single quote
/*
* Exercise 2-3. Write a function htoi(s), which converts a string of hexadecimal
* digits (including an optional 0x or 0X) into its equivalent integer value. The
* allowable digits are 0 through 9, a through f, and A through F.
*/
#include <stdio.h>
#include <stdlib.h>
#define BASE 16
#define TRUE 1
#define FALSE 0