Ubuntu and Win10 - double OS


  • 2016-02-21

Yesterday I helped my friend install Ubuntu (14.04 LTS) on his PC where there has been a MS Win10.
I used UltraISO to create a U-disk installation and installed it.
However, then we could only start up Ubuntu and there was no Win10.
Then we use LaoMaoTao software to rescue Win10's loader, while the Ubuntu disappeared.
Then we use EasyBCD on Win10 to add an Ubuntu loader.
Bingo!


Modify a binary file in Linux


  • 2016-02-28

Here is a helloworld.c:

#include <stdio.h>

int main()
{
    printf("Hello, world\n");
    return 0;
}

gcc -o helloworld helloworld.c

Then I want to change the string "Hello, world" to "hello, world".

Here is :

vim helloworld -b      # -b means binary
:%!xxd                 # observe in hex mode
# move cursor to letter 'H' and change it to 'h'
:%!xxd -r              # recover from text to binary
:wq

bingo!


Get file-size on Linux


  • 2016-02-29

Here is an interesting question that how can I get the file size in Linux environment.

Method.1

#include <stdio.h>

FILE *fp = fopen(filename, "r");
if(!fp)
    return -1;
fseek(fp, 0L, SEEK_END);
int size=ftell(fp);
printf("size is %d\n", size);
fclose(fp);

However, this method must load the whole file into memory. If the file is very large, its speed will be ridiculous!

Method.2

#include <sys/stat.h>
#include <stdio.h>

struct stat statbuf;
int state = stat(filename, &statbuf);
if(state < 0)
    return -1;
int size = statbuf.st_size;
printf("size is %d", size);

Bingo!


Win7 installation - GPT & MBR - Problems


  • 2016-02.29

Today my friend want to install Win7. I use a U-disk with LaoMaotao software and Win7 GHO. However, his disk is GPT mode.
The Win7 should be installed in MBR mode by default.
So we use LaoMaotao to change the disk into MBR mode.

P.S. Maybe we should also study how to install Win7 in GPT mode for the reason that GPT will be in fashion from now on.

bingo!


Editors in Linux automatically add '\n' to a file


  • 2016-03-01

Today I use Vim to create a text file and store it. Then I use 'xxd' to observe that file. Here is a '\x0a' at the end of the text.
And gedit will do so. Somebody says that is because of the canonical mode in Linux.


<Backspace> makes no effect in Vim & Vi


  • 2016-03-01

Today my friend uses Vi to edit a text. However he can't use to delete letters.
Here is the solution(Copy from Internet):

set nocompatible
set backspace=indent,eol,start


UTF-8 & Unicode & ASCII


  • 2016-03-02


execve - C function


  • 2016-03-03

Today I read CSAPP Chapter-8 and follow it to make a simple shell.
Here's the code:

        if(pid == 0){ // child runs user job
            if(execve(argv[0], argv, environ) < 0){
                printf("evecve error: %s\n", strerror(errno));
                printf("%s: Command not found.\n", argv[0]);
            }
        }

However, I can't use [echo "hello,world"] to execute [echo] instruction.
I must use [/bin/echo "hello,world"]. I have deliver the environment variables into the sub-process.
So, how can that thing happen?
After searching on the Internet, I know it.
[execve] belongs to a [exec] family. And there are some suffixes:

  • l // means that you must deliver the argv[0], argv[1]... one by one as variables and arguments end up with a NULL.
  • v // means that you should give a two-dimension pointer [**argv] as a variable. So you can't use suffix [v] and [l] at the same time.
  • p // means that you can use the $PATH environment variable to search for the argv[0] (filename).
  • e // means that you can deliver a [**envp] to give an environment to sub-process. Otherwise, the sub-process will use parent-process' environment.

Here are some functions:

  • execl
  • execv
  • execle
  • execlp
  • execvp
  • execve
  • execvpe

For the small shell above, we should use [execvpe] to replace [execve].
P.S.

for more details, please refer to [man execl] in Linux.

bingo!


stdin/stdout/stderr & STDIN_FILENO/STDOUT_FILENO/STDERR_FILENO


  • 2016-03-04

When I read CSAPP Chapter-8 there is a statement:

if((n = read(STDIN_FILENO, buf, sizeof(buf))) < 0)

What is [STDIN_FILENO] ?

[man read]
ssize_t read(int fd, void *buf, size_t count);

So STDIN_FILENO/STDOUT_FILENO/STDERR_FILENO are file descriptors.
They are [int] type.
And they are from <unistd.h>

Then, what about stdin/stdout/stderr ?

[man fread]
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);

So stdin/stdout/stderr are pointers.
They are [FILE *] type.
And they are from <stdio.h>

P.S.
[A] stdin/stdout/stderr
[B] STDIN_FILENO/STDOUT_FILENO/STDERR_FILENO

  • [A] belong to C standard library.
  • [B] belong to OS API library.
  • C standard library packages the OS API.
  • [A] are related to functions like fread,fwrite,fclose...
  • [B] are related to functions like read,write,close...(system call)

Bingo!


Go Into Console Interface Directly After startup [Linux]


  • 2016-03-04

This is a skill from my notebook.
environment: Ubuntu 14.04 LTS

sudo gedit /etc/default/grub

Find GRUB_CMDLINE_LINUX_DEFAULT
The key may be

"quiet splash"

Change it to

"quiet splash text"

Then

sudo update-grub

How to go into GUI when you are in text console:

sudo start lightdm

How to switch off GUI interface:

sudo stop lightdm


sizeof('A') Amazing !


  • 2016-03-04

This is a discovery from my notebook.
environment: Ubuntu 14.04 LTS

sizeof('A')
char a = 'A'
sizeof(a)
gcc...

Result will be 4, 1

g++...

Result will be 1, 1

Reason: The C language regards character constant as [int] type.


What is *nix ?


  • 2016-03-05

I have seen *nix for many times. I thought it was Unix and for some odd reasons it was writen as *nix.

But now I know that the * is a wildcard.
And the *nix means Unix and OS like Linux......

bingo!


Learn a new language as a professor


  • 2016-03-05

Today I begin to learn to use Python as a professor.
That means I plan to learn a new language without zero-based experience.
I have learnt C. And you know that for most languages there are just these things:

Data type or structure, control-instruction, other syntax.

Just read a manual, and practice, make mistakes, practice and make mistakes.
Then you will be familiar with it.
Don't simply learn it. Use it. Love it.


Why Can't I Use mov [mem], [mem] ?


  • 2016-03-09

I have learnt Assembly language for some time.
It confuses me for a long time that why the instruction mov [mem], [mem] is invalid.
Somebody says that it is because the designers of Intel CPU didn't design such a instruction.
But Why they didn't?
I believe that they must know that idea at least.
And they designed what we use today for some reasons I think.
Why?


No bool Type in C ?


  • 2016-03-09

Today when I use gcc to compile a .c file it informed me that there was no bool* type.....
Oh, my god. How can that be!
Then I search for the answer on the Internet and look up in K&R.
It seems that there is no bool type in C.......It is in C++......
So?

You can use some methods to make it:

// method 1
#include <stdbool.h>  // from C99

Or, just use g++ (method 2)

Also, you can use

// method 3
typedef int BOOL;
#define TRUE 1
#define FALSE 0
// method 4
typedef enum{TRUE = 1, FALSE = 0}BOOL;

bingo!


Copy/Past Shortcuts in Linux console


  • 2016-03-11

Ctrl + Shift + C // Copy
Ctrl + Shift + V // Paste


Use Wget and Bash to Backup My Blog


  • 2016-03-12

I want to backup blogs in cnblogs.
With the idea and help of my friend, here is the method:

First, you need to learn some wget-options:

-r # recursive
-b # background
-o FILE # log all messages to FILE (to std error by default)
-a FILE # similart to -o, while it is append
--quiet # turn off output
-i # you can select a text of URLs to download
--spider # Do not download; Just check
-x # --force-directories
-l depth # recursive depth
-np # no parent websites (when recursive)
-k # change the links for local viewing
-P PATH # specify the download directory
--accept-regex urlregex # use regular expressions to indicate what websites you want to be downloaded
--reject-regex urlregex # object functions to option --accept-regex urlregex
-p # --page-requisites ; download all the elements to show a website

Now, we use a bash script:

#!/bin/bash

# get date and time
x=$(date +back%Y%m%d%H%M) 

# make a directory named with data and time
mkdir $x  

# back up blog to the directory above
wget -r -p -k -x --accept-regex "http://www.cnblogs.com/00100011F" \
    http://www.cnblogs.com/00100011F -P $x

# download images in articles
d1='w*'
d2='00100011F'
d3='p'
d4='blogimages'
cd $x
cd $d1
cd $d2
cd $d3
mkdir $d4
cat * | grep img | grep -v 'logo' | cut -d '"' -f 2 | xargs wget -P $d4

P.S.

  • here is another wonderful instruction:
    wget -r -p -np -k -P Path URL # to download a whole website

bingo!


Configure Brightness on Ubuntu


  • 2016-03-31

The brightness on Ubuntu is 100 by default.
You can configure it and don't bother to change it by yourself each time you turn on your laptop.

Note that

/sys/class/backlight/acpi_video0/brightness

will dynamically record current brightness.

And

/etc/rc.local

This script is executed at the end of each multiuser runlevel.

You can add one instruction here before exit 0:

sudo echo 52 > /sys/class/backlight/acpi_video0/brightness
exit 0 # (This instruction is original there)

bingo!


Use GPG to Encrypt/Sign


  • 2016-04-21


Layer Mind


  • 2016-04-29


Markdown2PDF


  • 2016-07-12

Long time no see.
Today I want to transform markdown file into PDF format. So I use the print function of firefox. First you can export the markdown file to HTML format. Then open HTML file in firefox and choose file -> print -> print to file. (In fact my markdown editor haroopad has print function like firefox itself so I can transform the file directly...)
: )


Usual tiny skills & solutions的更多相关文章

  1. CRM 2011 Install Errors - Tips and Tricks continued(转)

    The more I get to install/upgrade to CRM 2011 in different environment the more I come across differ ...

  2. 10 Skills Every SharePoint Developer Needs

    10 Skills Every SharePoint Developer Needs(原文) This blog post guides you through the essential skill ...

  3. 15 Top Paying IT Certifications In 2016: AWS Certified Solutions Architect Leads At $125K

    Each of the five Amazon Web Services (AWS) certifications brings in an average salary of more than $ ...

  4. New Year, New Devs: Sharpen your C# Skills

    At the beginning of each new year, many people take on a challenge to learn something new or commit ...

  5. Virtualization solutions on Linux systems - KVM and VirtualBox

    Introduction Virtualization packages are means for users to run various operating systems without &q ...

  6. [转]Microsoft Solutions Framework (MSF) Overview

    本文转自:http://msdn.microsoft.com/zh-CN/library/jj161047(v=vs.120).aspx [This documentation is for prev ...

  7. .NET平台开源项目速览(14)最快的对象映射组件Tiny Mapper

    好久没有写文章,工作甚忙,但每日还是关注.NET领域的开源项目.五一休息,放松了一下之后,今天就给大家介绍一个轻量级的对象映射工具Tiny Mapper:号称是.NET平台最快的对象映射组件.那就一起 ...

  8. Tiny Mapper

    今天看到一个对象映射工具-TinyMapper 1.介绍 Tiny Mapper是一个.net平台的开源的对象映射组件,其它的对象映射组件比如AutoMapper有兴趣的可以去看,Tiny Mappe ...

  9. Design Tiny URL

    Part 1: 前言: 最近看了一些关于短址(short URL)方面的一些博客,有些博客说到一些好的东西,但是,也不是很全,所以,这篇博客算是对其它博客的一个总结吧. 介绍: 短址,顾名思义,就是把 ...

随机推荐

  1. mongoose - 让node.js高效操作mongodb

    Mongoose库简而言之就是在node环境中操作MongoDB数据库的一种便捷的封装,一种对象模型工具,类似ORM,Mongoose将数据库中的数据转换为JavaScript对象以供你在应用中使用. ...

  2. cookies如何成为全局变量以及设置,删除,获取

    (一)cookie机制将信息存储于用户硬盘,因此可以作为全局变量 (1)保存用户登录状态.例如将用户id存储于一个cookie内,这样当用户下次访问该页面时就不需要重新登录了,现在很多论坛和社区都提供 ...

  3. 简单使用Git和Github来管理自己的代码和读书笔记

    原文链接:http://my.oschina.net/bxxfighting/blog/378196   先注册github.com的账号官方网站: https://github.com/ 注册界面, ...

  4. react+redux教程(五)异步、单一state树结构、componentWillReceiveProps

    今天,我们要讲解的是异步.单一state树结构.componentWillReceiveProps这三个知识点. 例子 这个例子是官方的例子,主要是从Reddit中请求新闻列表来显示,可以切换reac ...

  5. 真实记录疑似Linux病毒导致服务器 带宽跑满的解决过程

    案例描述 由于最近我在重构之前的APP,需要和server端进行数据交互,发现有一个现象,那么就是隔1~2天总会发生获取数据超时的问题,而且必须要重启服务器才能解决.早在之前,我有留意到这个问题,但是 ...

  6. [摘录]第三部分 IBM文化(1)

    第二十章 论公司文化如果是在20世纪90年代初期,当一个人看见或者听到“IBM”时,他会联想到什么呢?或许是“大计算机”.“个人电脑”或者“ThinkPads”.但是,他们同时也必然会想到“大公司”. ...

  7. SQL Tuning 基础概述05 - Oracle 索引类型及介绍

    一.B-Tree索引 三大特点:高度较低.存储列值.结构有序 1.1利用索引特性进行优化 外键上建立索引:不但可以提升查询效率,而且可以有效避免锁的竞争(外键所在表delete记录未提交,主键所在表会 ...

  8. struts2工作流程

    struts2的框架结构图 工作流程 1.客户端请求一个HttpServletRequest的请求,如在浏览器中输入http://localhost: 8080/bookcode/Reg.action ...

  9. asp.net MVC 应用程序的生命周期

    下面这篇文章总结了 asp.net MVC 框架程序的生命周期.觉得写得不错,故转载一下. 转载自:http://www.cnblogs.com/yplong/p/5582576.html       ...

  10. JQuery Datatables Columns API 参数详细说明

    ---恢复内容开始--- Data Tables: http://datatables.NET/ Version: 1.10.0 Columns说明 虽然我们可以通过DOM直接获取DataTables ...