Sunday, December 14, 2014

MYSQL Server - Root password cannot login how!

/etc/init.d/mysql stop

Create a text file
UPDATE mysql.user SET Password=PASSWORD('XXX') WHERE User='root';
FLUSH PRIVILEGES;

Start MySQL in safe mode with init file
mysqld_safe --init-file=/path/of/your/file

Stop and start the mysql server and you should be able to login!
:)

Saturday, December 13, 2014

Python - Dad Chinese Subtitles - Creating the correct chinese srt file

And so usually i will have some problems downloading movies for my dad.

My dad have strict criteria for those movies.
They must be high res ( 480p and above ) and MUST Have chinese subtitles as his "english" isnt that great....

And which movies usually has chinese subtitles?

Not a lot....

And so, there is a need for the english subtitles to be translated to chinese and "hopefully" be playable in his VLC.

But the translated "chinese" file converted using google translate is unable to play well... because there seems to be font error on the timecode... so... here is a "tested only once" script that seems to work...

=== CODE ===

#!/usr/bin/python
import sys

with open("english.srt") as f:
english_content = f.readlines()

with open("chinese.srt") as f:
chinese_content = f.readlines()

#print english_content[0]
#print english_content[1]
#print english_content[2]
#print chinese_content[2]

def keeporthrow(mystring):
try:
int(mystring[0])
return True
except ValueError:
return False

#print keeporthrow(english_content[1])
#print keeporthrow(english_content[2])

if (len(english_content) != len(chinese_content)):
print "English file: " + str(len(english_content))
print "Chinese file: " + str(len(chinese_content))
print "Rows count dont match!"
exit

for i in range(0,len(english_content)):
#for i in range(0,10):

if keeporthrow(english_content[i]):
print english_content[i].rstrip('\n')
else:
if len(chinese_content[i]) == 1:
sys.stdout.write("\r\n")
else:
print chinese_content[i].rstrip('\n')

=== CODE ===

Monday, December 01, 2014

Disable local delivery Linux

What I did to disable local delivery. I'll be using the example.com domain.
Requirements:
  • example.com A entry pointing to IP address assigned to one of the eth interfaces.
  • /etc/hosts defining example.com assigned to the very same IP address as above
  • example.com MX records pointing to Google servers (ASPMX.L.GOOGLE.COM, etc)
  • default sendmail installation (mine was on Ubuntu)
Steps:
vim /etc/mail/sendmail.mc
at the end:
define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl
and then:
sendmailconfig (or /etc/mail/make depending on your distro)
service sendmail restart
testing:
echo -e "To: user@example.com\nSubject: Test\nTest\n" | sendmail -bm -t -v
echo -e "To: user\nSubject: Test\nTest\n" | sendmail -bm -t -v
You should see it connecting to the google server and then you should see your mail being delivered to your Google inbox.

Copied from : http://serverfault.com/questions/65365/disable-local-delivery-in-sendmail