闲来无事 / Nothing to Do with
耐心生活|小心生活|关心生活|粗心生活
Monday, March 18, 2013
Saturday, January 26, 2013
PHP5 FastCGI init.d scriipt for Debian/Ubuntu
Recently, I am using Nginx + PHP5 FastCGI as the new web platform. I really need a init.d script for PHP5 FastCGI. It is not so difficult according to the skeleton.
First of all, make sure to install php5-cgi and spawn-fcgi.
First of all, make sure to install php5-cgi and spawn-fcgi.
sudo apt-get install php5-cgi spawn-fcgiSecond, create the /etc/init.d/php-fastcgi script, as below:
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PHP5 FastCGI mode
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Yi Zhao
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="PHP5 FastCGI Service"
NAME=php5-cgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
SOCKET=/var/run/php-fastcgi.sock
PHP5=/usr/bin/php5-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
CHILDREN=2
DAEMON=/usr/bin/spawn-fcgi
DAEMON_ARGS="-s $SOCKET -C $CHILDREN -P $PIDFILE -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5"
# Exit if the package is not installed
[ -x "$DAEMON" -a -x "$PHP5" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
#. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --name $NAME
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
Add php-fastcgi into the start listsudo update-rc.d php-fastcgi defaultthis will start for init level 2,3,4,5
Thursday, April 12, 2012
Firefox 免插件 发 新浪 weibo 大法
Firefox 具有 Smart Keywords这个功能。她让我们可以 定义一个关键字 并用这个关键字来标示一个特定的网址。 利用这个功能,我们实际上可以做很多有趣的事情,比如发Sina围脖。 具体步骤如下:
- 使用 Firefox
- 打开 baidu.com 在搜索框上点右键
- 点 "Add Keyword for this Search..."
- 这时会弹出一个对话框, 在 "Name" 项输入 "sina weibo" 其实输入什么都可以, “keyword" 可以选 wb
- 然后保存
- 用 bookmark manager 打开这个新建的 Smart Keyword, 打开 properties 属性 对话框。然后在 “Location” 里面输入 下面的代码:
javascript:(function(){f='http://v.t.sina.com.cn/share/share.php?url='+encodeURIComponent(window.location.href)+'&title=%s';a=function(){if(!window.open(f,'location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))location.href=f};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()
这就全部搞定了! 今后 在任何一个网页, 你只要切换到Address Bar。 可以用Ctrl+D/Ctrl+L 快速切换。 然后输入: wb 任何你想输入的文字。 回车, 这就会打开一个新的窗口/tab 提示你 围脖的内容。Over!
Friday, May 06, 2011
How to create a MS Windows local account by program
There are several ways to make it happen:
- PowerShell solution: http://stackoverflow.com/questions/383390/create-local-user-with-powershell-windows-vista
- .Net solution: http://msdn.microsoft.com/en-us/library/bb384369.aspx#Y200
- Using Active Directory Service Interfaces (ADSI) COM: http://msdn.microsoft.com/en-us/library/aa705985(v=vs.85).aspx
Friday, April 22, 2011
Pointers to class member functions are always interesting
This FAQ show us lot of interesting things.
Wednesday, April 20, 2011
Celerbrate my StackOverflow.com account get over 2000 reputations
费尽九牛二虎之力 终于让我在StackOverflow的账号reputation 过了2000!
Monday, February 28, 2011
List of freely available programming books
Meta-List
- How to Design Programs: An Introduction to Computing and Programming
- 25 Free Computer Science Ebooks
- Free Tech Books
- MindView Inc (List of Free Books)
- Wikibooks: Programming
- Cheat Sheets (Free)
- CodePlex List of Free E-Books
- Book Training - On Video!
- Sofware Program Managers Network - Free EBooks
- EBook Share @ linbai.info
- FreeBooksClub.Net
- Theassayer.org (Free Online books)
- O'Reilly's Open Books Project
- TechBooksForFree.com
- Galileo Computing (Free Downloadable German Books)
Graphics Programming
- Nvidia GPU Gems 1
- Nvidia GPU Gems 2
- Nvidia GPU Gems 3
- Graphics Programming Black Book
- Wolfgang Engel ShaderX
Language Agnostic:
- Object-Oriented Reengineering Patterns
- Foundations of Programming by Karl Seguin
- Computer Musings (Lectures by Donald Knuth)
- The Cathedral and the Bazaar (Introduction to Open Source Software)
- Patterns and Practices: Application Architecture Guide 2.0
- Security Engineering
- Digital Signal Processing For Engineers and Scientists
- Getting Real (Courtesy 37 Signals)
- Structure and Interpretation of Computer Programs
- Domain Driven Design Quickly
- OO Design
- Best Kept Secrets of Peer Code Review
- NASA Software Measurement Handbook
- NASA Manager Handbook for Software Development
- Introduction to Functional Programming - Class Lectures and Slides
- How to Design Programs - MIT Press
- Guide to the Software Engineering Body of Knowledge - IEEE Computer Society Press
- Online Course Materials - MIT
- Algorithms (Draft Copy)
- Data Structures and Algorithms
- Essential Skills for Agile Development
- Programming Languages: Application and Interpretation
- Learn to Program
- Patterns of Software: Tales from the Software Community
- How to write Unmaintainable Code
- The Art of Unix Programming
- The Definitive Guide to Building Code Quality
- How to Think Like a Computer Scientist
- Planning Algorithms
- The Little Book of Semaphores
- Mathematical Logic - an Introduction
- An Introduction to the Theory of Computation
- Developers Developers Developers Developers
- Linkers and loaders
- Beej's Guide to Network Programming
- Domain Driven Design Quickly
- Let's Build a Compiler
- Producing Open Source Software
- How to Write Parallel Programs
- Don't Just Roll the Dice
- 97 Things Every Programmer Should Know
- How Computers Work
- Introduction to Information Retrieval - Cambridge University Press. 2008.
- Is Parallel Programming Hard, And, If So, What Can You Do About It?
- Matters Computational - Springer, 2010
- Type Theory and Functional Programming - Addison-Wesley, 1991
ASP.NET MVC:
Assembly Language:
- ProgrammingGroundUp
- Paul Carter's Tutorial on x86 Assembly
- Software optimization resources by Agner Fog
Bash
C/C++
- The new C standard - an annotated reference
- The C book
- Thinking in C++, Second Edition
- C++ Annotations
- Software optimization resources by Agner Fog
- Introduction to Design Patterns in C++ with Qt 4 (Open Publication License) (PDF)
C#
- See .NET below
Django
Erlang
F#
Forth
Git
Grails - Getting Start with Grails
Haskell
HTML
Java
- Sun's Java Tutorials
- Thinking in Java
- How to Think Like a Computer Scientist
- Java Thin-Client Programming
- OSGi in Practice (CreativeCommons Attribution Non-commercial Share Alike License)
JavaScript
- Eloquent JavaScript
- Crockford's JavaScript
- jQuery Fundamentals (starts with JavaScript basics)
- JavaScript Guide (Mozilla Developer Network)
- Essential Javascript & jQuery Design Patterns for Beginners
Linux
Lisp
- Practical Common Lisp
- On Lisp
- ANSI Common Lisp
- Common Lisp the Language, 2nd Edition
- Successful Lisp
- Let Over Lambda - 50 Years of Lisp
Lua
- Programming In Lua (for v5 but still largely relevant)
- Lua Programming Gems not entirely free, but has a lot of free chapters and accompanying code.
Maven
- Better Builds with Maven
- Maven by Example
- Maven: The Complete Reference
- Repository Management with Nexus
- Developing with Eclipse and Maven
Mercurial
.NET (C#)
- Free C# Book Covers C#1.0 and 2.0 (Courtesy of Programmers Heaven)
- Visual Studio Tips and Tricks (VS 2003-2005 only)
- Entity Framework (514 pages)
- Charles Petzold's .NET Book 0
- Threading in C#
- C# Yellow Book (Intro to programming)
- C# Programming - Wikibook
- C# Essentials
- Data Structures and Algorithms with Object-Oriented Design Patterns in C#
- Illustrated C# 2008 (Download) (.ZIP) [dead link]
- O'Reilly's C# Pocket Reference Manual (Free Ebook courtesy of Red Gate Software) [dead link]
NoSQL
Objective-C
Oracle Server
- Oracle Guides and Manuals
Oracle PL/SQL
- PL/SQL Language Reference
- PL/SQL Packages and Types Reference
- Steven Feuerstein's PL/SQL Obsession - Videos and Presentations
Parrot / Perl 6
- Perl 6 (Work in progress)
Perl
- Higher-Order Perl
- Perl The Hard Way
- Extreme Perl
- Perl Free Online EBooks Meta-List
- The Mason Book
- Practical mod_perl
- Beginning Perl
- Embedding Perl in HTML with Mason (Open Publication License)
- Perl & LWP
- Perl for the Web
- Web Client Programming with Perl
- Modern Perl 5
PHP
- Practical PHP Programming (Wiki that contains O'Reilly's PHP In a Nutshell)
- Zend Framework: Survive the Deep End
PowerShell
Prolog
- Building Expert Systems in Prolog
- Adventure in Prolog
- Prolog Programming A First Course
- Logic, Programming and Prolog (2ed)
- Introduction to Prolog for Mathematicians
- Learn Prolog Now!
- Natural Language Processing Techniques in Prolog
- Prolog techniques
- Applications of Prolog
- Simply logical
PostgreSQL
Python
- Dive Into Python
- Dive Into Python 3
- Byte of Python
- Building Skills in Python Version 2.5
- Python Free Online Ebooks Meta-List
- Python Bibliotheca
- Think Python
- Data Structures and Algorithms in Python
- How to Think Like a Computer Scientist: Learning with Python
- Python for Fun
- Invent Your Own Computer Games With Python
- Learn Python The Hard Way
- Thinking in Python
- The Django Book
- Snake Wrangling For Kids
- Natural Language Processing with Python (nltk-book)
Ruby
- Programming Ruby
- Why's (Poignant) Guide to Ruby (Mirror via Scribd)
- Mr. Neighborly's Humble Little Ruby Book
- Ruby Best Practices
- MacRuby: The Definitive Guide
- Ruby on Rails Tutorial: Learn Rails By Example
Scala
- A Scala Tutorial for Java programmers
- Scala By Example
- Programming Scala
- Xtrace (Github)
- List (Github)
- Pro Scala: Monadic Design Patterns for the Web
- Exploring Lift (published earlier as "The Definitive Guide to Lift", pdf)
Scheme
Smalltalk
- Smalltalk Free Ebooks Courtesy of Stéphane Ducasse
- Squeak By Example (Smalltalk IDE)
Subversion
- Subversion Version Control: Using the Subversion Version Control System in Development Projects
- Version Control with Subversion
SQL (Implementation agnostic)
- Developing Time-Oriented Database Applications in SQL,Richard T. Snodgrass
- Use The Index, Luke! - A guide to SQL database performance for developers
Vim
Subscribe to:
Posts (Atom)