Mind Mining Medium

Programming category archive

Better array search

July 21st, 2009 | Programming, regular | No comments

Update: Added more data to show differences.
During the journey of finding a better linear array search function in javascript, I decided to write my own. I decided to take a different approach. Here’s the outcome.

Array.prototype.small_search = function(search) {
if (this[0] === search){ return 0; }
var s = ‘\x00′;
[...]

How To: Splitting large text files into smaller ones

May 29th, 2009 | Programming, regular | No comments

Let’s say you have a huge text file with couple million lines. Now you want to split it up into 100, 200, or 300 line files. Bash makes it pretty easy with split.
In Bash:

split -l 500 file.txt

That splits up the file file.txt into 500 line chunks. What is produced are files such as xaa, xab, [...]

How To: Find the size of a directory

May 28th, 2009 | Programming, regular | No comments

Sometimes it’s very useful to know how much content is in a directory without opening a GUI interface.
In Bash:

du -cks * | sort -n | awk ‘\”BEGIN { split(”KB,MB,GB,TB”, Units, “,”); } { u = 1;while ($1 >= 1024){$1 = $1 / 1024;u += 1;}$1 = sprintf(”%.1f %s”, $1, Units[u]);print $0;}’\” | tail -11

I would [...]

How To: Remove Duplicate Lines From A File

May 28th, 2009 | Programming, regular | No comments

Sure you can load up a bulky editor and use its tools to do that, but why not do it in much faster in bash with awk.
In Bash:

awk ‘!x[$0]++’ in.txt > out.txt

Wasn’t that easy?

Command, Option, & Shift Symbols in Unicode

May 27th, 2009 | Programming, regular | No comments

Unicode does define some other characters which are sort of Mac-specific.
⌘ – ⌘ – ⌘ – the Command Key symbol
⌥ – ⌥ – ⌥ – the Option Key symbol
⇧ – ⇧ – ⇧ – the Shift Key symbol
⎋ – ⎋ – ⎋ – the Power Button
Note: The Power Button and Shift Key are not Mac-specific. [...]

Keyboard Shortcut to Help Search Box

May 27th, 2009 | Programming, regular | No comments

If you haven’t figured out how Mac OS X 10.5 (Leopard) help search box allows you to search menu items, check out Chris Pirillo demoing the feature.
The problem for me is that I’m a keyboard person. Over 90% of my day, I barely touch the mouse. Now, to get to the help search bar with [...]

Find & Replace in Linux/Mac

May 27th, 2009 | Programming, regular | No comments

This is a quick one liner to find and replace strings in *nix. You can use this in your Mac terminal or Unix prompt.
In Bash:

find ./ -type f -exec sed -i ’s/FIND/REPLACE/g’ {} \;

Example:

find ./ -type f -exec sed -i ’s/signin/login/g’ {} \;

Firefox & Input Field Width

May 26th, 2009 | Programming, regular | No comments

Hate the 2px difference you get when you apply a width on your input fields in Firefox?
Try this in CSS:

input, textarea, select{-moz-box-sizing: border-box;}

See how many Kernel Panics your Mac has had

May 26th, 2009 | Programming, regular | No comments

In bash:

ls -1 /Library/Logs/PanicReporter/ | wc -l

I’ve had 5.

Scroll to bottom of page.

May 22nd, 2009 | Programming, regular | No comments

In javascript:

window.scroll(0, window.document.height);