Script

Filter
2009-01-03

Använd S.M.A.R.T. för att kolla dina hårddiskar

Linux
Har du en server i garderoben? För att kontrollera om det är för varmt för hårddiskarna kan du använda dej av smartmontools.
1. Installera.
apt-get install smartmontools

2. Kolla vad dina diskar heter:
parted
> print all

3. smartctl -A /dev/sda (eller /dev/sdc etc)

4. Läs mer:
man smartctl
2008-12-08

Tillägg i Firefox

Tips & tricks
En massa bra tillägg för webbutvecklaren
Web Developer
Mycket bra multiverktyg

Firebug
Multiverktyg för att inspektera kod mm

MeasureIt
Mäter ytors pixelvärden

EditCSS
Visar redigerbar CSS i sidopanel

JSView
Visar externa (javascript o CSS) filer

NoScript
Blockera Java o javascript temporärt eller permanent

LinkChecker
Kollar länkar

FireFTP
FTP-klient i webbläsaren

User Agent Switcher
Få Firefox att tro att den är IE, Opera eller Netscape

Quick Locale Switcher
Växla språk

Live HTTP Headers
Kolla headerinfo i sidpanel

YSlow
Kräver Firebug. Kontrolerar nedladdningstider

ColorZilla
Kontrollera och kopiera färger
2008-10-16

Sök och ändra i Vim

Linux
Här är några exempel hämtade från http://vim.wikia.com/wiki/Search_and_replace
Use the :substitute command to search for a text pattern, and replace it with a text string.

There are many options, but these are what you most probably want:

:%s/foo/bar/g
    Find each occurrence of 'foo', and replace it with 'bar'. 

:%s/foo/bar/gc
    Change each 'foo' to 'bar', but ask for confirmation first. 

:%s/\<foo\>/bar/gc
    Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation. 

:%s/foo/bar/gci
    Change each 'foo' (case insensitive) to 'bar'; ask for confirmation. 

:%s/foo/bar/gcI
    Change each 'foo' (case sensitive) to 'bar'; ask for confirmation. 

The g flag means global — each occurrence in the line is changed, rather than just the first.

Search range:

    The % in :%s applies the substitute to every line in the buffer, rather than just the current line. 
    :5,12s/foo/bar/g will change each 'foo' to 'bar' for all lines between line 5 and line 12. 
    :'a,'bs/foo/bar/g will change each 'foo' to 'bar' for all lines between marks a and b. 
    :.,$s/foo/bar/g will change each 'foo' to 'bar' for all lines between the current line (.) and the last line ($). 
    :.,+2s/foo/bar/g will change each 'foo' to 'bar' for the current line (.) and the two next lines (+2). 
    (Note that :%s is equivalent to :1,$s.) 

When searching:

    \/ is / (use backslash + forward slash to search for forward slash) 
    \t is tab, \s is whitespace 
    \n is newline, \r is CR (carriage return = Ctrl-M = ^M) 

When replacing:

    \r is newline, \n is a null byte (0x00). 
    \& is ampersand (& is the search pattern). 

You can use other delimiters with substitute:

    :s#http://www.example.com/index.html#http://example.com/# 

This can be a very helpful technique, because you can avoid escaping a / character if you use something other than / for a delimiter, and some delimiters such as ; may be faster/easier to type.

Save typing by using \zs and \ze to set the start and end of a pattern. For example, instead of:

    :s/Copyright 2007 All Rights Reserved/Copyright 2008 All Rights Reserved/ 

You could try:

    :s/Copyright \zs2007\ze All Rights Reserved/2008/


Praktiskt exempel: För att ta bort radmatningar i slutet på varje rad:
%s/\r//g
2008-07-10

Char sets i mysql

Mysql
Några korta tips om hur mysql hanterar olika teckenuppsättningar
Fråga om hur värdena är inställda (i mysql-tolken):
SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

(Ändra med SET NAMES 'charset_name'
A SET NAMES 'x' statement is equivalent to these three statements: 
SET character_set_client = x;
SET character_set_results = x;
SET character_set_connection = x;)

Vad händer vid en sql-fråga:
1. Klient sänder fråga: character_set_client
2. Server tar emot: character_set_connection
3. Server bearbetar resultat: character_set_results

Andra variabler:
character_set_system
character_set_server
character_set_database (default-character-set i /var/lib/mysql/<db_namn>/db.opt)

You must also consider the environment within which your MySQL application executes.
For example, if you will send statements using UTF-8 text taken from a file that you create in an editor,
you should edit the file with the locale of your environment set to UTF-8 so that the file's encoding is
correct and so that the operating system handles it correctly. For a script that executes in a Web environment,
the script must handle the character encoding properly for its interaction with the MySQL server,
and it must generate pages that correctly indicate the encoding so that browsers know now to display
the content of the pages. 

Ändra char set:
ALTER TABLE mytablename DEFAULT COLLATE utf8_general_ci;
ALTER TABLE Table1 MODIFY column1 VARCHAR(5) CHARACTER SET latin1 COLLATE latin1_swedish_ci;

I my.cnf:
[client]
default-character-set=utf8

[mysqld]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqladmin]
default-character-set=utf8

[mysqlcheck]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

[mysqlimport]
default-character-set=utf8

[mysqlshow]
default-character-set=utf8
2008-07-10

Ubuntu Dapper root user

Ubuntu
How to switch to root user in console
sudo -s -H
Password: <specify user password>

Enklare variant:
sudo su
Password: <specify user password>
🙂