Regex to Make Text Links HTML Links

Regex used to select and replace URLs in plain text with clickable links



$regex = '(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.%-=#~\@!]*(\?\S+)?)?)?)';
$text = mb_ereg_replace($regex, '<a href="\\1">\\1</a>', $text);

Python Multiprocessing

The following code will enable you to implement multiprocessing in any Python project that contains a for loop. Take your for loop that has a long-running function in it and replace “for i in iterable” with your for loop conditions. Change “function_name” to the name of the function that will be executed. Change the list of function arguments to what you need.

import multiprocessing
number_cores = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=number_cores)
r = [pool.apply_async(function_name, args=(function_arg1, function_arg2)) for i in iterable]
output = [p.get() for p in r]

The above code would be the multiprocessing implementation of the following.

output = []
for i in iterable:
    output += function_name(function_arg1, function_arg2)

Regex Sentence Splitter

Regex to match the end of sentences in order to split a block of text into sentences.


Python Code

sentence_regex = ur'([\.\?!][\'\"\u2018\u2019\u201c\u201d\)\]]*\s*(?<!\w\.\w.)(?<![A-Z][a-z][a-z]\.)(?<![A-Z][a-z]\.)(?<![A-Z]\.)\s+)'
regex = re.compile(sentence_regex, flags=re.UNICODE)
sentences = regex.split(TEXT_BLOCK)

Using Synology NAS as CrashPlan Backup Destination

When I first got my Synology DS1815+ to replace my existing file server that was using Windows Storage Spaces on Windows 10, I was excited to continue using CrashPlan to backup my family’s computers. Unfortunately, I soon found out that while the Synology can run CrashPlan after reading the tutorial from PCLoadLetter, it was not anything like I was used to for administration. Using CrashPlan installed on the Synology required modifying configuration files on all of the computers that I wanted to backup, instead of simply logging into my CrashPlan account as I had done before. So, I promptly gave up and used Synology’s Cloud Station Backup for 6 months. 

Continue reading → Using Synology NAS as CrashPlan Backup Destination

JavaScript Offline 2 Factor Authentication

This project source can be found on my github here.

This project is a single webpage to calculate time based tokens for two factor authentication, just like Google Authenticator or Authy does on your phone. There is no network connection necessary, so it can be used offline and you can be sure that I am not stealing your codes.

The project can be used live here.

Continue reading → JavaScript Offline 2 Factor Authentication