技术小黑屋

How to Create a .db File in Python With Sqlite3

How to create a .db file in Python with sqlite3?Actually It’s really easy.
Run the following code

1
2
import sqlite3
sqlite3.connect('./test.db')

After running the above code,the test.db file will be created if it does not exist.
Of course,you have the proper permission to create the file.

Yum Install Build-essentials

I was once stucked in installing build-essentials which is for Debian/Ubuntu.I could not find any packages like build-essentials in yum.However this helped me out.

1
sudo yum install kernel-devel kernel-headers

Javac:command Not Found

I have been getting well on with my java tool.However When I use the javac command.It says

1
javac : command not found

It’s just because I just only install the JRE(Java Runtime Environment) and do not install JDK(Java Development KIt).I got the answer going for my fedora

1
sudo yum install java-devel

Others

Manage Httpd Service

To Start

1
sudo /sbin/service httpd start

To Stop

1
sudo /sbin/service httpd stop

To Restart

1
sudo /sbin/service httpd restart

List Ports on Linux

I have often suffered this painful thing.When I start a service but the destination port is always used.So I should list all open ports and kill the occupied application.
So This is a short tip for how to list open ports on Linux

1
sudo netstat -tulpn

Note sometimes you should grant the command for a enough access.
For a better understanding,please

1
man netstat

or navigate to http://linux.about.com/od/commands/l/blcmdl8_netstat.htm

For Mac Users

1
sudo lsof -i -P | grep -i "listen"

Others

How to Find Out What Linux Distribution You Are Using

How to known what Linux Distribution I am using now.
All right, run this command and you could get what you need in from the output result

1
2
3
4
5
6
7
8
9
10
11
19:12:17-androidyue~/github/octopress (master)$ cat /etc/*-release
Fedora release 17 (Beefy Miracle)
NAME=Fedora
VERSION="17 (Beefy Miracle)"
ID=fedora
VERSION_ID=17
PRETTY_NAME="Fedora 17 (Beefy Miracle)"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:17"
Fedora release 17 (Beefy Miracle)
Fedora release 17 (Beefy Miracle)

How to Delete Git Remote Branches

It’s easy to remove a certain remote branch in a Git respository. You could try this

1
git push origin --delete <branchName>

And of course another short command is waiting for You

1
git push origin :<branchName>

Accelerate Yum Installation

Yum is a great tool for manage dependencies and easy to use.However actually there is a way to speed up the installation.
Fastestmirror is a tool that will help yum determin what mirror is fastest and to use.
To install on Fedora 17

1
sudo yum install yum-fastestmirror

Of course you could customize the fastestmirror configuration easily

1
sudo vim /etc/yum/pluginconf.d/fastestmirror.conf

So when you next install a package from the network,I hope you could feel it much faster.

How to Sum the Number of Files or Folders in a Folder

I once had a request to sum the number of files in a specific folder.After googling I found the command wc could help me out.
wc – print newline, word, and byte counts for each file. And I think wc is short for Word Count.Please have a detailed information by visiting http://linux.about.com/library/cmd/blcmdl1_wc.htm if you have the desire.
Ok,Let’ get the total number of files(including folders) in a specific folder

1
20:56:08-androidyue/tmp$ ls | wc

Well,the following command will sum the number of pure files(Not including folders)

1
20:58:27-androidyue/tmp$ ll | grep ^- | wc

However how to sum the number of pure folder?The following command will help.

1
21:00:20-androidyue/tmp$ ll | grep ^d | wc

Install Git Daemon on Fedora

Git-daemon is A really simple server for git repositories.You can take a detailed understanding by reading https://www.kernel.org/pub/software/scm/git/docs/git-daemon.html .
I once often used git-daemon when I was using Ubuntu.But when I turn to Fedora and found it was not installed.And the output is like the following.

1
git: 'daemon' is not a git command. See 'git --help'.

So I write this post to record How to install and enable git-daemon First Let’s intall the git Daemon:

1
sudo yum install git-daemon

However git daemon is off by default.We should enable it.We should do as the following.

1
vim  /etc/xinetd.d/git

And modify the file as the following configuration.

# default: off
# description: The git dæmon allows git repositories to be exported using \
        #       the git:// protocol.

service git
{
            disable         = no
            socket_type     = stream
            wait            = no
            user            = nobody
            server          = /usr/libexec/git-core/git-daemon
            server_args     = --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
            log_on_failure  += USERID
            # xinetd does not enable IPv6 by default
            flags           = IPv6

}

And then,We use this command to start the git Daemon

1
git  daemon--export-all--base-path=your_local_git_path

Mostly we could clone the repositories from the git daemon.
But if you have enabled Firewall and other people want to clone the repository from your git daemon,please let the port 9418 available to the outsite.

BashBites:How to Append Outputs to a File

Is there any way to append output(debugging information) to a existings file? As we all know in bash the command ‘>’ will write ouputs to a file.However this command will also erase the existing data it the file.
Of course bash provides a command that appends outputs to a file.It resembles ‘>’.It’s ‘>>’
The following is a piece of example code.

Let’s look at >
1
2
3
4
5
6
7
8
[androidyue@androidyue tmp]$ touch a.txt
[androidyue@androidyue tmp]$ cat a.txt
[androidyue@androidyue tmp]$ echo "ABC" > a.txt
[androidyue@androidyue tmp]$ cat a.txt
ABC
[androidyue@androidyue tmp]$ echo "DEF" > a.txt
[androidyue@androidyue tmp]$ cat a.txt
DEF
Well,Let’s look at the exiciting command >>
1
2
3
4
[androidyue@androidyue tmp]$ echo "GHI" >> a.txt
[androidyue@androidyue tmp]$ cat a.txt
DEF
GHI

Install Flash Plugin on Fedora 17

Addings
1
2
3
4
5
6
#For 32-bit System:
sudo rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
#For 64-bit System 
sudo rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm

sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
Updatings
1
sudo yum update
Installings
1
sudo yum install flash-plugin nspluginwrapper alsa-plugins-pulseaudio libcurl

Issues About Installing Octopress

Actually I am fresh to Write Blog with Octopress in Github Pages.According to the Introduction .And now I have make it avaible and the website is present. However I have suffered some problems when I did the setup.Here is a summary of what I have sufferd and how I resolved.

Could not find rdiscount-2.0.7.3 in any of the sources Run bundle install to install missing gems.
source ~/.rvm/scripts/rvm
rvm use 1.9.3 --default 
I have used rake preview ,But I got 404 when I open the http://127.0.0.1:4000
[androidyue@androidyue octopress]$ rake preview
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
[2013-09-07 15:46:20] INFO  WEBrick 1.3.1
[2013-09-07 15:46:20] INFO  ruby 1.9.3 (2013-06-27) [i686-linux]
[2013-09-07 15:46:20] INFO  WEBrick::HTTPServer#start: pid=10490 port=4000
Configuration from /home/androidyue/github/octopress/_config.yml
Auto-regenerating enabled: source -> public/
[2013-09-07 15:46:21] regeneration: 95 files changed
>>> Change detected at 15:46:21 to: screen.scss
   create public/github/stylesheets/screen.css 
   Errno::ENOENT on line ["56"] of /home/androidyue/.rvm/gems/ruby-1.9.3-p448/gems/compass-0.12.2/lib/compass/actions.rb: No such file or directory - /home/androidyue/github/octopress/public/github/stylesheets/screen.css
   Run with --trace to see the full backtrace]

As the above information and all the sources are outputed in public/ folder And the following are a part of my _config.yml file

# If publishing to a subdirectory as in http://site.com/project set 'root: /project'
root: /
permalink: /blog/:year/:month/:day/:title/
source: source
destination: public/
plugins: plugins
code_dir: downloads/code
category_dir: blog/categories

So compare the two piece information and check the output dir and is public or a subdirectory in public folder.If your outputdir is a subdirectory you should use this link http://127.0.0.1:4000/yourSubDirName P.S.This is the help from StackOverflow http://stackoverflow.com/questions/17465404/rake-preview-not-working-in-octopress

I will keep record about this topic becuase I am making friends with Octopress in Github Pages

My First Blog

Hello World,This page is a playgroud for using Octopress and markdown language.Thanks for my GirlFriend’s support!
Common Code
echo "Hello World";
Python Code
1
2
from os import system
system('ls')
Java Code
1
String s = "Hello World";
Bash Code
1
2
mkdir test
ls
List
  • item1
  • item2