Author Archives: Raymond

About Raymond

I'm a Christian web developer from the Philippines. Sometimes I write also.

sed edit in place deleting matching lines

This command deletes the line that contains “remove-matching-line” in files that matches *.txt wildcard. $ ls -1 *.txt | xargs -I ‘{}’ sed -i ‘/^.*remove-matching-line.*$/d’ ‘{}’ A hacker inserted eval(base64_decode(“obfuscated_code”)) on a client’s PHP files. I used this command to … Continue reading

Posted in Bash script, Linux | Tagged , | Leave a comment

Remove duplicates from MySQL Table

ALTER IGNORE TABLE categories ADD PRIMARY KEY(categories_id);

Posted in MySQL, SQL | Tagged , | Leave a comment

Create Linux RAID Level 1 from 4 TB Harddisk

Partition the disk into two equal parts. # parted /dev/sda GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type ‘help’ to view a list of commands. (parted) mklabel gpt (parted) print Model: Areca ARC-1212-VOL#000 (scsi) Disk /dev/sda: 4,00TB Sector … Continue reading

Posted in Uncategorized | Leave a comment

Vim set file encoding

:set bomb :set fileencoding=utf-8

Posted in Uncategorized | Tagged , | Leave a comment

MySQL regex update

Simple solution: UPDATE  table SET     words = REPLACE(words, ‘brown’, ‘green’) WHERE   words REGEXP ‘brown ‘ OR words REGEXP ‘ brown’ Better solution from http://techras.wordpress.com/2011/06/02/regex-replace-for-mysql/: SET sql_mode=’NO_BACKSLASH_ESCAPES’; DELIMITER $$ CREATE FUNCTION `regex_replace`(pattern VARCHAR(1000),replacement VARCHAR(1000),original VARCHAR(1000)) RETURNS VARCHAR(1000) DETERMINISTIC BEGIN DECLARE temp … Continue reading

Posted in MySQL | Leave a comment

Number format by country

Source: International Number Formats Format Country 1,234.56 – Invariant Language (Invariant Country) ar-SA – Arabic (Saudi Arabia) zh-TW – Chinese (Taiwan) en-US – English (United States) he-IL – Hebrew (Israel) ja-JP – Japanese (Japan) ko-KR – Korean (Korea) th-TH – … Continue reading

Posted in General | Tagged | Leave a comment

Bash: getting confirmation to continue or exit

  #!/bin/bash while true do read -r -p ‘Are you sure? ‘ choice case “$choice” in y|Y) echo “Processing…” break ;; n|N) echo “Canceled.” exit ;; esac done echo “Complete.”

Posted in Linux | Tagged | Leave a comment

Currency Internationalization (i18n), Multiple Currencies and Foreign Exchange (FX)

Currency Internationalization (i18n), Multiple Currencies and Foreign Exchange (FX)

Posted in web | Tagged | Leave a comment

Multibyte PHP Functions

Source: Using Multi-Byte Character Sets in PHP (Unicode, UTF-8, etc) The following list details the PHP string functions which could cause problems when handling multi-byte strings. The multi-byte safe alternative is given when available: mail() Try mb_send_mail() instead. strlen() Try mb_strlen() instead. strpos() Try mb_strpos() instead. … Continue reading

Posted in PHP | Tagged , , | Leave a comment

Force secure browsing https

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} dir RewriteRule ^(.*)$ https://www.example.com/dir/$1 [R,L]

Posted in Uncategorized | Tagged , | Leave a comment