<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Subjectively</title>
	<atom:link href="http://kirk.webfinish.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kirk.webfinish.com</link>
	<description>dd if=/dev/random &#124; kirk &#62; blog</description>
	<lastBuildDate>Wed, 04 Jan 2012 15:48:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://kirk.webfinish.com/?pushpress=hub'/>
		<item>
		<title>Split a text file into chunks by line count</title>
		<link>http://kirk.webfinish.com/2012/01/split-a-text-file-into-chunks-by-line-count/</link>
		<comments>http://kirk.webfinish.com/2012/01/split-a-text-file-into-chunks-by-line-count/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 15:47:21 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=203</guid>
		<description><![CDATA[This is a simple splitter for text files by line count. Input File with 4 lines: input.txt this is line 1 this is line 2 this is line 3 this is line 4 ./chunkfile -f input.txt -c 4 -j 2 -p output or cat input.txt &#124; ./chunkfile.sh -c 4 -j 2 -p output -e txt [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple splitter for text files by line count.  </p>
<p>Input File with 4 lines: input.txt<br />
this is line 1<br />
this is line 2<br />
this is line 3<br />
this is line 4</p>
<p>./chunkfile -f input.txt -c 4 -j 2 -p output<br />
  or<br />
cat input.txt | ./chunkfile.sh -c 4 -j 2 -p output -e txt</p>
<p>Output will be:<br />
  Output:<br />
  output_01.txt<br />
  output_02.txt<br />
  output_03.txt<br />
  output_04.txt</p>
<p>With a single line of text in each file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#          FILE:  chunkfile.sh</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#         USAGE:  ./chunkfile.sh </span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  split a text file by lines</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#       OPTIONS:  ---</span>
<span style="color: #666666; font-style: italic;">#  REQUIREMENTS:  ---</span>
<span style="color: #666666; font-style: italic;">#          BUGS:  ---</span>
<span style="color: #666666; font-style: italic;">#         NOTES:  ---</span>
<span style="color: #666666; font-style: italic;">#        AUTHOR:  Kirk Roybal (DBA), kroybal@kalkomey.com</span>
<span style="color: #666666; font-style: italic;">#       COMPANY:  Kalkomey</span>
<span style="color: #666666; font-style: italic;">#       VERSION:  1.0</span>
<span style="color: #666666; font-style: italic;">#       CREATED:  12/30/2011 09:45:42 AM CST</span>
<span style="color: #666666; font-style: italic;">#      REVISION:  ---</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
&nbsp;
&nbsp;
<span style="color: #007800;">ScriptVersion</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#         NAME:  usage</span>
<span style="color: #666666; font-style: italic;">#  DESCRIPTION:  Display usage information.</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> usage <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;</span>- EOT
&nbsp;
  Usage :  <span style="color: #800000;">${0##/*/}</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>options<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>--<span style="color: #7a0874; font-weight: bold;">&#93;</span> 
&nbsp;
  Options: 
  <span style="color: #660033;">-c</span><span style="color: #000000; font-weight: bold;">|</span>chunks <span style="color: #666666; font-style: italic;">#   Number of chunks</span>
  <span style="color: #660033;">-d</span><span style="color: #000000; font-weight: bold;">|</span>debug      Display <span style="color: #c20cb9; font-weight: bold;">bash</span> debugging info
  <span style="color: #660033;">-e</span><span style="color: #000000; font-weight: bold;">|</span>ext  exten Output <span style="color: #c20cb9; font-weight: bold;">file</span> extension
  <span style="color: #660033;">-f</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">file</span> name  File to chunk
  <span style="color: #660033;">-h</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">help</span>       Display this message
  <span style="color: #660033;">-j</span><span style="color: #000000; font-weight: bold;">|</span>just pad   Padding zeros <span style="color: #000000; font-weight: bold;">for</span> output files
  <span style="color: #660033;">-l</span><span style="color: #000000; font-weight: bold;">|</span>log        Display logging information
  <span style="color: #660033;">-p</span><span style="color: #000000; font-weight: bold;">|</span>prefix pre Prefix of new <span style="color: #c20cb9; font-weight: bold;">file</span> names
  <span style="color: #660033;">-v</span><span style="color: #000000; font-weight: bold;">|</span>version    Display script version
&nbsp;
  Note:  using multiple logging options increases the log level
  <span style="color: #7a0874; font-weight: bold;">&#40;</span>i.e.<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #800000;">${0##/*/}</span> <span style="color: #660033;">-lll</span> <span style="color: #660033;">-f</span> input.txt <span style="color: #660033;">-c</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-j</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-p</span> output
  Log level <span style="color: #000000;">3</span>.
&nbsp;
  Output:
  output_01.txt
  output_02.txt
  output_03.txt
&nbsp;
&nbsp;
	EOT
<span style="color: #7a0874; font-weight: bold;">&#125;</span>    <span style="color: #666666; font-style: italic;"># ----------  end of function usage  ----------</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#  Handle command line arguments</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
&nbsp;
<span style="color: #007800;">padding</span>=<span style="color: #000000;">2</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;:c:de:f:hj:lp:v&quot;</span> opt
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$opt</span> <span style="color: #000000; font-weight: bold;">in</span>
&nbsp;
    c<span style="color: #000000; font-weight: bold;">|</span>chunks   <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">chunks</span>=<span style="color: #007800;">$OPTARG</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    d<span style="color: #000000; font-weight: bold;">|</span>debug    <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-x</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    e<span style="color: #000000; font-weight: bold;">|</span>ext      <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">ext</span>=<span style="color: #ff0000;">&quot;.<span style="color: #007800;">$OPTARG</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    f<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">file</span>     <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">filename</span>=<span style="color: #007800;">$OPTARG</span>
                  <span style="color: #007800;">ext</span>=<span style="color: #ff0000;">&quot;.<span style="color: #007800;">${filename#*.}</span>&quot;</span>
                  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$prefix</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">prefix</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(basename ${filename} $ext)</span>_&quot;</span>
                  <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    h<span style="color: #000000; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">help</span>     <span style="color: #7a0874; font-weight: bold;">&#41;</span>  usage; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>   <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    j<span style="color: #000000; font-weight: bold;">|</span>just     <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">padding</span>=<span style="color: #007800;">$OPTARG</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    l<span style="color: #000000; font-weight: bold;">|</span>log      <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> logging++ <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    p<span style="color: #000000; font-weight: bold;">|</span>prefix   <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">prefix</span>=<span style="color: #007800;">$OPTARG</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    v<span style="color: #000000; font-weight: bold;">|</span>version  <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$0 -- Version <span style="color: #007800;">$ScriptVersion</span>&quot;</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>   <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    \? <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>  Option does not exist : <span style="color: #007800;">$OPTARG</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
          usage; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>   <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">esac</span>    <span style="color: #666666; font-style: italic;"># --- end of case ---</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">shift</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$OPTIND</span>-<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$filename</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$prefix</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;</span>- EOT
&nbsp;
  You must specify a filename or a prefix <span style="color: #000000; font-weight: bold;">for</span> output.
  <span style="color: #7a0874; font-weight: bold;">&#40;</span>i.e.<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #800000;">${0##/*/}</span> <span style="color: #660033;">-f</span> input.txt <span style="color: #660033;">-c</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-j</span> <span style="color: #000000;">2</span> 
  or
  <span style="color: #7a0874; font-weight: bold;">&#40;</span>i.e.<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> input.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #800000;">${0##/*/}</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-j</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-p</span> output
&nbsp;
	EOT
  usage
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#take input from stdin</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$filename</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">filename</span>=<span style="color: #ff0000;">&quot;-&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$chunks</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  usage
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">guts</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">tempfile</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$filename</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$guts</span>&quot;</span>
&nbsp;
<span style="color: #007800;">filesize</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$guts</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">chunksize</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>filesize<span style="color: #000000; font-weight: bold;">/</span>chunks<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>filesize<span style="color: #000000; font-weight: bold;">%</span>chunks<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> chunksize++<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>;i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #007800;">$chunks</span>;i++<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">dest</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${prefix}</span><span style="color: #007800;">$(printf &quot;%0${padding}i&quot; $(($i + 1)</span>))<span style="color: #007800;">$ext</span>&quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$guts</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-n</span> +$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$i</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #007800;">$chunksize</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> 
    <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$chunksize</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dest</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$guts</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$guts</span>&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2012/01/split-a-text-file-into-chunks-by-line-count/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bulk load csv data from bash into mysql with LOAD DATA LOCAL INFILE</title>
		<link>http://kirk.webfinish.com/2011/12/bulk-load-csv-data-from-bash-into-mysql-with-load-data-local-infile/</link>
		<comments>http://kirk.webfinish.com/2011/12/bulk-load-csv-data-from-bash-into-mysql-with-load-data-local-infile/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 22:58:38 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=196</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#          FILE:  csv2mysql.sh</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#         USAGE:  ./csv2mysql.sh </span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#   DESCRIPTION:  Import data into mysql from csv</span>
<span style="color: #666666; font-style: italic;">#                     ignore flag fields along the way.</span>
<span style="color: #666666; font-style: italic;">#       OPTIONS:  ---</span>
<span style="color: #666666; font-style: italic;">#  REQUIREMENTS:  ---</span>
<span style="color: #666666; font-style: italic;">#          BUGS:  ---</span>
<span style="color: #666666; font-style: italic;">#         NOTES:  ---</span>
<span style="color: #666666; font-style: italic;">#        AUTHOR:  Kirk Roybal (Operations Manager), kroybal@kalkomey.com</span>
<span style="color: #666666; font-style: italic;">#       COMPANY:  Kalkomey</span>
<span style="color: #666666; font-style: italic;">#       VERSION:  1.0</span>
<span style="color: #666666; font-style: italic;">#       CREATED:  12/13/2011 15:31:50 CST</span>
<span style="color: #666666; font-style: italic;">#      REVISION:  ---</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
&nbsp;
<span style="color: #007800;">host</span>=192.168.101.125
<span style="color: #007800;">user</span>=root
<span style="color: #007800;">inputfile</span>=product1.csv
<span style="color: #007800;">sep</span>=,
<span style="color: #007800;">table</span>=kris_inventory_sims
<span style="color: #007800;">database</span>=
&nbsp;
&nbsp;
<span style="color: #007800;">ScriptVersion</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#===  FUNCTION  ================================================================</span>
<span style="color: #666666; font-style: italic;">#         NAME:  usage</span>
<span style="color: #666666; font-style: italic;">#  DESCRIPTION:  Display usage information.</span>
<span style="color: #666666; font-style: italic;">#===============================================================================</span>
<span style="color: #000000; font-weight: bold;">function</span> usage <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;</span>- EOT
&nbsp;
  Usage :  <span style="color: #800000;">${0##/*/}</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>options<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>--<span style="color: #7a0874; font-weight: bold;">&#93;</span> 
&nbsp;
  Options: 
  <span style="color: #660033;">-d</span><span style="color: #000000; font-weight: bold;">|</span>debug      Display <span style="color: #c20cb9; font-weight: bold;">bash</span> debugging info
  <span style="color: #660033;">-h</span><span style="color: #000000; font-weight: bold;">|</span>host name  Server Name or IP
  <span style="color: #660033;">-i</span><span style="color: #000000; font-weight: bold;">|</span>input <span style="color: #c20cb9; font-weight: bold;">file</span> Filename to load
  <span style="color: #660033;">-l</span><span style="color: #000000; font-weight: bold;">|</span>log        Display logging information
  <span style="color: #660033;">-s</span><span style="color: #000000; font-weight: bold;">|</span>sep char   <span style="color: #000000;">1</span> Character field sep
  <span style="color: #660033;">-t</span><span style="color: #000000; font-weight: bold;">|</span>table name Data Table to load
  <span style="color: #660033;">-u</span><span style="color: #000000; font-weight: bold;">|</span>user name  Database username
  <span style="color: #660033;">-v</span><span style="color: #000000; font-weight: bold;">|</span>version    Display script version
&nbsp;
  Note:  using multiple logging options increases the log level
  <span style="color: #7a0874; font-weight: bold;">&#40;</span>i.e.<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #800000;">${0##/*/}</span> <span style="color: #660033;">-lll</span>
  Log level <span style="color: #000000;">3</span>.
&nbsp;
  <span style="color: #800000;">${0##/*/}</span> <span style="color: #660033;">-h</span> 192.168.101.125 <span style="color: #660033;">-u</span> root <span style="color: #660033;">-d</span> KE_IC <span style="color: #660033;">-t</span> kris_inventory_sims <span style="color: #660033;">-i</span> product1.csv
  <span style="color: #800000;">${0##/*/}</span> <span style="color: #660033;">-h</span> 192.168.101.125 <span style="color: #660033;">-u</span> root <span style="color: #660033;">-d</span> KE_IC <span style="color: #660033;">-t</span> ocr_header <span style="color: #660033;">-i</span> ocr.csv
&nbsp;
	EOT
<span style="color: #7a0874; font-weight: bold;">&#125;</span>    <span style="color: #666666; font-style: italic;"># ----------  end of function usage  ----------</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
<span style="color: #666666; font-style: italic;">#  Handle command line arguments</span>
<span style="color: #666666; font-style: italic;">#-----------------------------------------------------------------------</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">getopts</span> <span style="color: #ff0000;">&quot;:dh:i:ls:t:u:v&quot;</span> opt
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$opt</span> <span style="color: #000000; font-weight: bold;">in</span>
&nbsp;
    d<span style="color: #000000; font-weight: bold;">|</span>db       <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">database</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTARG</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    h<span style="color: #000000; font-weight: bold;">|</span>host     <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">host</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTARG</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    i<span style="color: #000000; font-weight: bold;">|</span>input    <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">inputfile</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTARG</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    l<span style="color: #000000; font-weight: bold;">|</span>log      <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> logging++ <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;  <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$logging</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-x</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    s<span style="color: #000000; font-weight: bold;">|</span>sep      <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">sep</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTARG</span>{0:1}&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    t<span style="color: #000000; font-weight: bold;">|</span>table    <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">table</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTARG</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    u<span style="color: #000000; font-weight: bold;">|</span>user     <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OPTARG</span>&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    v<span style="color: #000000; font-weight: bold;">|</span>version  <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$0 -- Version <span style="color: #007800;">$ScriptVersion</span>&quot;</span>; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>   <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    \? <span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>  Option does not exist : <span style="color: #007800;">$OPTARG</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
          usage; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>   <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">esac</span>    <span style="color: #666666; font-style: italic;"># --- end of case ---</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">shift</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$OPTIND</span>-<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#CREATE TABLE `ocr_header` (</span>
<span style="color: #666666; font-style: italic;">#  `companyid` varchar(11) COLLATE utf8_unicode_ci DEFAULT NULL,</span>
<span style="color: #666666; font-style: italic;">#  `id` int(11) NOT NULL AUTO_INCREMENT,</span>
<span style="color: #666666; font-style: italic;">#  `table_id` int(11) NOT NULL DEFAULT '0',</span>
<span style="color: #666666; font-style: italic;">#  `table_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,</span>
<span style="color: #666666; font-style: italic;">#  `doc_type` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,</span>
<span style="color: #666666; font-style: italic;">#  `keywords` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,</span>
<span style="color: #666666; font-style: italic;">#  PRIMARY KEY (`id`)</span>
<span style="color: #666666; font-style: italic;">#) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#get a field list</span>
<span style="color: #007800;">fields</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql <span style="color: #660033;">-h</span> <span style="color: #007800;">$host</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$user</span> <span style="color: #007800;">$database</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;SHOW CREATE TABLE <span style="color: #007800;">$table</span>;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> 
  gsed <span style="color: #ff0000;">'s/\\n/\n/g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'^[[:space:]]'</span> <span style="color: #000000; font-weight: bold;">|</span> 
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^[^[:alnum:]]*//'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/`.*,/,/g'</span> <span style="color: #000000; font-weight: bold;">|</span>
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^date_stamp,$/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^id,$/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/ KEY /d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^user_id,$/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^loaded_from,$/d'</span> <span style="color: #000000; font-weight: bold;">|</span>
  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'$s/,//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#note that id is intentionally missing</span>
<span style="color: #666666; font-style: italic;"># and lack of comma on last line</span>
<span style="color: #666666; font-style: italic;">#companyid,</span>
<span style="color: #666666; font-style: italic;">#table_id,</span>
<span style="color: #666666; font-style: italic;">#table_name,</span>
<span style="color: #666666; font-style: italic;">#doc_type,</span>
<span style="color: #666666; font-style: italic;">#keywords</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#LOAD DATA LOCAL INFILE 'product1.csv'</span>
<span style="color: #666666; font-style: italic;">#INTO TABLE ocr_header</span>
<span style="color: #666666; font-style: italic;">#FIELDS TERMINATED BY ','</span>
<span style="color: #666666; font-style: italic;">#OPTIONALLY ENCLOSED BY &quot;&quot;&quot;&quot;</span>
<span style="color: #666666; font-style: italic;">#LINES TERMINATED BY '\n' </span>
<span style="color: #666666; font-style: italic;">#(</span>
<span style="color: #666666; font-style: italic;">#companyid,</span>
<span style="color: #666666; font-style: italic;">#table_id,</span>
<span style="color: #666666; font-style: italic;">#table_name,</span>
<span style="color: #666666; font-style: italic;">#doc_type,</span>
<span style="color: #666666; font-style: italic;">#keywords</span>
<span style="color: #666666; font-style: italic;">#)</span>
&nbsp;
<span style="color: #007800;">nl</span>=<span style="color: #ff0000;">'\\n'</span>
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;
LOAD DATA LOCAL INFILE '<span style="color: #007800;">$inputfile</span>'
INTO TABLE <span style="color: #007800;">$table</span>
FIELDS TERMINATED BY '<span style="color: #007800;">$sep</span>'
OPTIONALLY ENCLOSED BY <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\&quot;</span>
LINES TERMINATED BY '<span style="color: #007800;">$nl</span>'&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span> 
(
<span style="color: #007800;">$fields</span>
)&quot;</span> <span style="color: #666666; font-style: italic;">#| mysql -h $host -u $user $database --local-infile</span>
&nbsp;
<span style="color: #007800;">sql</span>=<span style="color: #ff0000;">&quot;UPDATE <span style="color: #007800;">$table</span>
SET loaded_from = 'product1.csv',
user_id = 'klr'
WHERE loaded_from is null;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$sql</span>&quot;</span> <span style="color: #666666; font-style: italic;">#|  mysql -h $host -u $user $database</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/12/bulk-load-csv-data-from-bash-into-mysql-with-load-data-local-infile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate unique, non-sequential keys</title>
		<link>http://kirk.webfinish.com/2011/10/generate-unique-non-sequential-keys/</link>
		<comments>http://kirk.webfinish.com/2011/10/generate-unique-non-sequential-keys/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 21:25:22 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=192</guid>
		<description><![CDATA[This article demonstrates 3 different methods that I have found to create unique numbers that are non-sequential, do not overlap, and can be modified to produce a non-overlapping series in the future. They are *not* based on random numbers. The encoded series is completely deterministic. Coded in PHP. Hope this helps somebody who&#8217;s trying to [...]]]></description>
			<content:encoded><![CDATA[<p>This article demonstrates 3 different methods that I have found to create unique numbers that are non-sequential, do not overlap, and can be modified to produce a non-overlapping series in the future.  They are *not* based on random numbers.  The encoded series is completely deterministic.  Coded in PHP.  Hope this helps somebody who&#8217;s trying to come up with a numbering scheme that is forward supportable.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
  GetHandleForItemIndex
    Parameters: Integer
&nbsp;
  Given a series of integers, 
  output a different series that is non-contiguous,
    non-overlapping, and can be modified in the future
    not to overlap numbers that have been generated by
    the same input series.
&nbsp;
  input 1,2,3,4,5,6,7,8,9,10
  output 8400,35400,62400,89400,116400,143400,170400,197400,224400,251400
&nbsp;
  By changing the prime number constants, a completly different (and 
    non-overlapping) output series can be generated in the future.
&nbsp;
  GetItemIndexForHandle
    Parameters: Integer 
&nbsp;
  Translates the series back into simple decimal contiguous input.
&nbsp;
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#const PRIME_NUMBER_A = '65521';
</span><span style="color: #666666; font-style: italic;">#const PRIME_NUMBER_B = '999721';
</span><span style="color: #666666; font-style: italic;">#const PRIME_NUMBER_C = '145709';
</span><span style="color: #000000; font-weight: bold;">const</span> PRIME_NUMBER_A <span style="color: #339933;">=</span> <span style="color: #0000ff;">'2'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">const</span> PRIME_NUMBER_B <span style="color: #339933;">=</span> <span style="color: #0000ff;">'3'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">const</span> PRIME_NUMBER_C <span style="color: #339933;">=</span> <span style="color: #0000ff;">'5'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> GetHandleForItemIndex<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//$in =( PRIME_NUMBER_A*( $in +PRIME_NUMBER_A ) );</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_A<span style="color: #339933;">,</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_A <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_A<span style="color: #339933;">,</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_B <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_A<span style="color: #339933;">,</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_C <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_B<span style="color: #339933;">,</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_A <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_B<span style="color: #339933;">,</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_B <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_B<span style="color: #339933;">,</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_C <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_C<span style="color: #339933;">,</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_A <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_C<span style="color: #339933;">,</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_B <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span><span style="color: #990000;">bcmul</span><span style="color: #009900;">&#40;</span> PRIME_NUMBER_C<span style="color: #339933;">,</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #339933;">,</span>PRIME_NUMBER_C <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$in</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> GetItemIndexForHandle<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$in</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_C<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_C<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_C<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_C<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_B<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_C<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_B<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_B<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_C<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcadd</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_B<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$in</span> <span style="color: #339933;">=</span> <span style="color: #990000;">bcsub</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">bcdiv</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$in</span><span style="color: #339933;">,</span>PRIME_NUMBER_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>PRIME_NUMBER_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$in</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Obfuscation Demo&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;TABLE&gt;
<span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000088;">$h</span> <span style="color: #339933;">=</span>GetHandleForItemIndex<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;TR&gt;&lt;TD&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/TD&gt;&lt;TD&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/TD&gt;&lt;/TR&gt;&quot;</span><span style="color: #339933;">,</span> GetItemIndexForHandle<span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//print GetHandleForItemIndex('1000000000');</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/*
  rot10enc
    Parameters: Integer
&nbsp;
  Encodes an integer with a simple substitution cipher,
    and then reverses the order of magnitude of the digits.
    The least significant digit is used to reorder an input
    list into non-contiguous, 'unordered' output series.
&nbsp;
  Input  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
  Output 6,5,7,4,8,3,9,0,2,1,65,55,75,45,85,35,95
&nbsp;
  Still somewhat easily predictable, but discourages use
    of the integer for anything other than an identifier.
&nbsp;
  rot10dec
    Original series is easily retrieved.
&nbsp;
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">const</span> ROT10 <span style="color: #339933;">=</span> <span style="color: #0000ff;">'6574839021'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">const</span> ROT01 <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> rot10enc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">&lt;</span>strlen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$idx</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #000088;">$j</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span>ROT10<span style="color: #339933;">,</span><span style="color: #000088;">$idx</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">strrev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> rot10dec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">&lt;</span>strlen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$idx</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span>ROT10<span style="color: #339933;">,</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #000088;">$j</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$idx</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> rot10enc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;TR&gt;&lt;TD&gt;%s&lt;/TD&gt;&lt;TD&gt;%s&lt;/TD&gt;&lt;/TR&gt;'</span><span style="color: #339933;">,</span> rot10dec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$j</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/*
&nbsp;
  Convert an input integer to any arbitrary base encoding.
    base30 is given as an example.  Note that 3,T,0,O 
    are intentionally missing to illustrate use of this function
    for creating serial numbers that are easily legible.
&nbsp;
  Also, a base conversion to a nonsense encoding illustrates using
    this algorithm to create a non-contiguous, non-repeating series.
&nbsp;
  This can be modified to produce non-overlapping series by changing
    either 1) the characters used in the encoding 2) the order of magnitude
    of the input series.
&nbsp;
INPUT   0,1,2,3,4,5,6,7,8,9,10
OUTPUT  9,A,8,B,7,C,6,D,5,E,4
&nbsp;
  Further obfuscation is also possible by reversing the order of the
    resulting series digits, so the least significant digit becomes the
    most significant sorting digit.
&nbsp;
*/</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">const</span> base30a <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ABCDEFGHJKLMNPQRSUVWXYZ2456789'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">const</span> base30x <span style="color: #339933;">=</span> <span style="color: #0000ff;">'9A8B7C6D5E4F2GZHYJXKWLVMUNSPQR'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">const</span> base62 <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">const</span> basex <span style="color: #339933;">=</span> base30x<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">const</span> baselen <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># 30/62
</span>
<span style="color: #000000; font-weight: bold;">function</span> dec2base<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span>basex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span> <span style="color: #339933;">&gt;=</span> baselen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$magnitude</span><span style="color: #339933;">++;</span>
      <span style="color: #000088;">$base</span> <span style="color: #339933;">/=</span> baselen<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$idx</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$msd</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span>basex<span style="color: #339933;">,</span><span style="color: #000088;">$idx</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$msd</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$idx</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span>baselen<span style="color: #339933;">,</span><span style="color: #000088;">$magnitude</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$idx</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i</span> <span style="color: #339933;">-=</span> <span style="color: #000088;">$idx</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$buffer</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span>basex<span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> base2dec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$magnitude</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#order of magnitude of digit
</span>    <span style="color: #000088;">$msd</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">#the most significant digit itself
</span>    <span style="color: #000088;">$idx</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span>basex<span style="color: #339933;">,</span><span style="color: #000088;">$msd</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#decimal position that digit appears in keyfield
</span>    <span style="color: #666666; font-style: italic;">#add the decimal value of the digit multiplied by it's order of magnitude
</span>    <span style="color: #000088;">$buffer</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span>baselen<span style="color: #339933;">,</span><span style="color: #000088;">$magnitude</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$idx</span><span style="color: #339933;">;</span>  
    <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#move on to the next digit
</span>  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$buffer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$blah</span> <span style="color: #339933;">=</span> dec2base<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;TR&gt;&lt;TD&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/TD&gt;&lt;TD&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/TD&gt;&lt;/TR&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$blah</span><span style="color: #339933;">,</span> base2dec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blah</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span> 
&nbsp;
&lt;/TABLE&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/10/generate-unique-non-sequential-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>43 grad war&#8217;s gestern</title>
		<link>http://kirk.webfinish.com/2011/08/43-grad-wars-gestern/</link>
		<comments>http://kirk.webfinish.com/2011/08/43-grad-wars-gestern/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 00:48:27 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/2011/08/43-grad-wars-gestern/</guid>
		<description><![CDATA[That&#8217;s 110 degrees for the rest of you out there.]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s 110 degrees for the rest of you out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/08/43-grad-wars-gestern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Socialized health care</title>
		<link>http://kirk.webfinish.com/2011/05/socialized-health-care/</link>
		<comments>http://kirk.webfinish.com/2011/05/socialized-health-care/#comments</comments>
		<pubDate>Sun, 15 May 2011 17:32:58 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=188</guid>
		<description><![CDATA[I was reading this discussion on Mark Drumms wall. There are many facts that I don&#8217;t think anybody is getting. A bit of background first. I spent almost 12 years in Germany. Many of those years I had AOK insurance, which is the mandatory minimum socialized insurance. Let me explain some of the &#8220;benefits&#8221; to [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading this discussion on <a href="http://www.facebook.com/permalink.php?story_fbid=218325038196879&#038;id=1218321492&#038;ref=notif&#038;notif_t=wall#!/permalink.php?story_fbid=202189156485011&#038;id=100000817839390">Mark Drumms wall</a>.  There are many facts that I don&#8217;t think anybody is getting.<br />
A bit of background first.  I spent almost 12 years in Germany.  Many of those years I had AOK insurance, which is the mandatory minimum socialized insurance.  Let me explain some of the &#8220;benefits&#8221; to you from the perspective of someone who has lived with it for an extended period of time.<br />
Europe had a very lopsided population spread after WWII.  Most of the aged adult population was dead.  In order to rebuild the country, migrant workers were brought in.  Most of those were from Turkey.  Germans started this system when the number of payers far exceeded the number of payouts.  Initially, it took many years from the time a dollar was put into the system to the time it was paid out to a citizen.  Migrants paid in, but were not expected to be there long enough to get a payout.<br />
The system was cash rich, and the benefits flowed in the land of milk and honey.  As the population aged, the payments began to have a much shorter gap to the payouts.  By the time I left in 1996, it was only about 3 months from input to output.  As the gap closed, the shenanigans began.<br />
Pharmaceuticals began to cost more to subsidize the system for the medical community.  The government responded by fixing the amount of money it was willing to pay on the mandatory insurance.  Private sector responded in kind by setting the prices at (go figure) EXACTLY the same price that the government would pay.   Initially, this was beneficial to the patient who needed expensive drugs, and detrimental to the guy who needed an aspirin.  Eventually, it was detrimental to everybody.  This system evolved into effective government price fixing of pharmaceuticals.<br />
The next measure was to start fixing the price of services.  This works very similar to what we do with HMO, so I won&#8217;t describe it in detail.  Suffice it to say that it was implemented nationwide, which disallowed any other choices.  Goodbye personal plans (PPO).  In order to qualify for those you had to make cutoff salaries that were far out of reach of the people that the mandatory insurance was originally intended to service.<br />
In order to stop the malpractice insurance problem that doctors have in the US, they simply limited the amount of money that could be awarded in a malpractice suit.  Sounds simple right?  Except that your life now has a very attainable price tag on it, and you would be an idiot to believe that the doctors don&#8217;t know exactly what it is.<br />
At this point, government officials sit in a room and argue over pennies of how much medicine should cost, whether it is financially viable to bother to save your life, whether your life is worth saving anyway, and whether or not they should get the &#8220;silver&#8221; wash or the &#8220;premium&#8221; wash on their Mercedes.<br />
The Europeans started this system when they were cash rich and payout poor.  How long to you think it will take the US to fail with this when we are deficit rich and government management idiots?</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/05/socialized-health-care/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paracord belt</title>
		<link>http://kirk.webfinish.com/2011/05/paracord-belt/</link>
		<comments>http://kirk.webfinish.com/2011/05/paracord-belt/#comments</comments>
		<pubDate>Tue, 10 May 2011 02:58:19 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Paracord belt]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/2011/05/paracord-belt/</guid>
		<description><![CDATA[I made this paracord belt several months ago, and it&#8217;s holding up really well. I forgot the name of the weave, I think it was dragontooth.]]></description>
			<content:encoded><![CDATA[<p><img style="display:block;margin-right:auto;margin-left:auto;" alt="image" src="http://kirk.webfinish.com/wp-content/uploads/2011/05/wpid-1304996266238.jpg" /></p>
<p>I made this paracord belt several months ago, and it&#8217;s holding up really well. I forgot the name of the weave, I think it was dragontooth.</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/05/paracord-belt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duct tape wallet for a moleskine and Zebra F701 pen</title>
		<link>http://kirk.webfinish.com/2011/05/duct-tape-wallet-for-a-moleskine-and-f701-pen/</link>
		<comments>http://kirk.webfinish.com/2011/05/duct-tape-wallet-for-a-moleskine-and-f701-pen/#comments</comments>
		<pubDate>Sat, 07 May 2011 22:05:25 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/2011/05/duct-tape-wallet-for-a-moleskine-and-f701-pen/</guid>
		<description><![CDATA[This is a pic of a duct tape wallet that I just made. What is hiding behind it is a 3.5&#215;5.5 moleskine with graph paper. I scavenged the picture window from an old wallet I had laying around. The front cover holds 6 cards nicely. I made the card pockets to fit the cards that [...]]]></description>
			<content:encoded><![CDATA[<p><img style="display:block;margin-right:auto;margin-left:auto;" alt="image" src="http://kirk.webfinish.com/wp-content/uploads/2011/05/wpid-1304805365906.jpg" /></p>
<p>This is a pic of a duct tape wallet that I just made. What is hiding behind it is a 3.5&#215;5.5 moleskine with graph paper. I scavenged the picture window from an old wallet I had laying around.<br />
The front cover holds 6 cards nicely.<br />
I made the card pockets to fit the cards that are in them. I wrapped the tape from the card pockets around the pen, with a little tape on the inside to keep the pen from sticking. Nothing but duct tape was used.<br />
The pen is a modified Zebra F701 from <a href="http://kirk.webfinish.com/2011/01/zebra-f701-pen-and-m701-pencil-set-with-serious-mods/">this post</a>.  The loop also fits the pencil.<br />
No animals were harmed in the making of this wallet, especially DUCKS.</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/05/duct-tape-wallet-for-a-moleskine-and-f701-pen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swype for android is awesome</title>
		<link>http://kirk.webfinish.com/2011/05/swype-for-android-is-awesome/</link>
		<comments>http://kirk.webfinish.com/2011/05/swype-for-android-is-awesome/#comments</comments>
		<pubDate>Sat, 07 May 2011 21:55:10 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/2011/05/swype-for-android-is-awesome/</guid>
		<description><![CDATA[I&#8217;ve been working with android for about a week now, and the swype keyboard has made my life a lot better. This post, for example, has been entered with swype in about 30 seconds.  If you only knew how painful that was with iPhone, you&#8217;d be impressed right now. Armed with an LG G2x on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with android for about a week now, and the swype keyboard has made my life a lot better. This post, for example, has been entered with swype in about 30 seconds.  If you only knew how painful that was with iPhone, you&#8217;d be impressed right now.<br />
Armed with an LG G2x on T-Mobile, you will start seeing a lot more posts from me in the field.<br />
onward and upward&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/05/swype-for-android-is-awesome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KA-BAR Becker Companion knife knock-off by United</title>
		<link>http://kirk.webfinish.com/2011/01/united/</link>
		<comments>http://kirk.webfinish.com/2011/01/united/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 07:43:40 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=169</guid>
		<description><![CDATA[KA-BAR Becker Companion knife knock-off by United...Here's the finished product.  It cost a grand total of 36.88 plus a little paracord I had lying around which is probably worth about $2.]]></description>
			<content:encoded><![CDATA[<p>Ok, what I really wanted was this <a href="https://www.kabar.com/product/productDetail.do?productNumber=BK7&#038;mode=category&#038;categoryId=1,2,3,7&#038;categoryName=Military/Tactical">KA-BAR Becker Combat Utility Knife</a>.  Once again with the caviar tastes and beer budget.<br />
So I&#8217;m browsing through the Knife Shoppe in the Arlington mall, and come across this United knife in a kydex sheath that&#8217;s a dead ringer for the KA-BAR.  Wonder of wonders, it costs 35 bucks.<br />
On the way out of the store with my new knife, I think about how I&#8217;m going to mod it up.  It has a lanyard hole begging for some paracord, strap loops and eyelets in the kydex sheath for a leg strap.<br />
Here&#8217;s a picture of what happens when you leave me alone with a new knife and paracord for a few minutes.<br />
<div id="attachment_170" class="wp-caption alignnone" style="width: 235px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0042.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0042-225x300.jpg" alt="box weave on united knife" title="box weave on united knife" width="225" height="300" class="size-medium wp-image-170" /></a><p class="wp-caption-text">box weave on united knife</p></div><br />
I also bought a simple nylon strap and buckle at WallyWorld for $1.88.<br />
<div id="attachment_171" class="wp-caption alignnone" style="width: 310px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0043.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0043-300x225.jpg" alt="Nylon utility strap" title="Nylon utility strap" width="300" height="225" class="size-medium wp-image-171" /></a><p class="wp-caption-text">Nylon utility strap</p></div><br />
Here&#8217;s the finished product.  It cost a grand total of 36.88 plus a little paracord I had lying around which is probably worth about $2.<br />
<div id="attachment_172" class="wp-caption alignnone" style="width: 235px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0044.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0044-225x300.jpg" alt="United knife with box weave and thigh strap" title="United knife with box weave and thigh strap" width="225" height="300" class="size-medium wp-image-172" /></a><p class="wp-caption-text">United knife with box weave and thigh strap</p></div><br />
Sure beats $115 retail for the KA-BAR, and I&#8217;m not so worried about beating it up.  It&#8217;s already been to the woods a few times.  Processes wood like a champ, and I have batoned it through several logs with no ill effect other than losing a little blade coating.  Since I can have 3 of these for the price of a KA-BAR, I&#8217;m way happy with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/01/united/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zebra F701 pen and M701 pencil set (with serious mods)</title>
		<link>http://kirk.webfinish.com/2011/01/zebra-f701-pen-and-m701-pencil-set-with-serious-mods/</link>
		<comments>http://kirk.webfinish.com/2011/01/zebra-f701-pen-and-m701-pencil-set-with-serious-mods/#comments</comments>
		<pubDate>Sat, 01 Jan 2011 19:16:42 +0000</pubDate>
		<dc:creator>Kirk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kirk.webfinish.com/?p=149</guid>
		<description><![CDATA[At the end of this mod, you will have a F701 that has an all metal clicker and a fisher space pen refill, along with a *matching* pencil with a .5 mm nib (also with a metal clicker).]]></description>
			<content:encoded><![CDATA[<p>I love the Zebra F701 pen.<br />
I hate the Zebra F701 pen.<br />
Well, anyway, I hate the lack of choices for refills and the .7 mm pencil.  So, I decided to just roll my own Zebra pen and pencil set the way I wish they delivered it.<br />
At the end of this mod, you will have a F701 that has an all metal clicker and a fisher space pen refill, along with a *matching* pencil with a .5 mm nib (also with a metal clicker).<br />
Not possible, you say?  Actually it was pretty easy.<br />
You will need about $35 in supplies to make this work, including the pens.  This mod starts by taking apart a Zebra 402 pen/pencil set and using them for parts.  You will be able to make a &#8220;scrap&#8221; set with the leftovers when finished.  If you are more careful about it than me, that is.<br />
<div id="attachment_151" class="wp-caption alignnone" style="width: 310px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0035.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0035-300x225.jpg" alt="Zebra 402 pen/pencil set" title="Zebra 402 pen/pencil set" width="300" height="225" class="size-medium wp-image-151" /></a><p class="wp-caption-text">Zebra 402 pen/pencil set</p></div><br />
I got this set at Office Despot for about $8.50.  You will also need two (2) Zebra F701 pens.<br />
Start by putting the F402 pen in the refrigerator for 20 minutes.  While it is cooling, go find yourself a lighter.  When the time is up, take the pen out of the &#8216;fridge.  Heat the clicker end of the pen body with the lighter until the metal of the pen discolors slightly.  The different expansion and contraction rates of the metal and the plastic will cause the seal to break.  You can let it cool a little, and you should be able to unscrew the top with just finger pressure.  What you want to get out of it is this:<br />
<div id="attachment_152" class="wp-caption alignnone" style="width: 235px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0036.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0036-225x300.jpg" alt="Zebra F402 clicker assembly" title="Zebra F402 clicker assembly" width="225" height="300" class="size-medium wp-image-152" /></a><p class="wp-caption-text">Zebra F402 clicker assembly</p></div><br />
I heated mine waaay too long, and ended up with plastic slag inside the pen.  It didn&#8217;t matter for me, because I wasn&#8217;t trying to salvage the rest of the pen, but you might want to just go 10-15 seconds.  I&#8217;m not admitting to how long I heated mine.<br />
I was able to unscrew the clicker of the Zebra F701 with just my fingers.  I&#8217;m not sure that any normal human should be able to do this.  I have ridiculously strong fingers and forearms.  If you can&#8217;t, try using a pair of fine jewelry pliers.  Whatever you do, don&#8217;t do the cooling/heating trick above.  The internal parts of the F701 are ALL plastic, they will simply melt together.   The nib simply unscrews from the tip with simple finger pressure, just like putting in a new refill.<br />
<div id="attachment_153" class="wp-caption alignnone" style="width: 310px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0037.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0037-300x225.jpg" alt="fisher space pen refill and Zebra F701 spring" title="fisher space pen refill and Zebra F701 spring" width="300" height="225" class="size-medium wp-image-153" /></a><p class="wp-caption-text">fisher space pen refill and Zebra F701 spring</p></div><br />
Then I purchased a Fisher space pen refill.  The refill cost $4.44 at Office Despot.  Unfortunately, it does not come with a spring, since the fisher space pen is a solid body with a cap, not a retractable.  I salvaged the spring from the F701.  You will need to enlarge the nib of the F701 to be able to extend the point of the space pen refill.  I did this just by jamming the space pen refill up the nib backwards like so:<br />
<div id="attachment_154" class="wp-caption alignnone" style="width: 310px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0038.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0038-300x225.jpg" alt="Reaming out the F701 nib" title="Reaming out the F701 nib" width="300" height="225" class="size-medium wp-image-154" /></a><p class="wp-caption-text">Reaming out the F701 nib</p></div><br />
If you don&#8217;t want to bother with the space pen refill, you could also use the nib from the F402 to make the set match a little better.  The space pen refill does not fit through the F402 nib, no matter what I tried.<br />
Next, you want to take the M402 pencil apart.  Start by unscrewing the nib (once again, finger pressure will do).  This will expose a plastic valve and lead reservoir.  This plastic piece is has somewhat flattened sides just above the threaded end (close to the pencil body).  Find a small pair of pliers and unscrew this from the pencil body.  When it comes loose, you can slide it out of the pencil body with a little force.  Be careful not to crush the lead reservoir.  Just yank it from the tip.<br />
<div id="attachment_155" class="wp-caption alignnone" style="width: 310px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0039.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0039-300x225.jpg" alt="M402 pencil guts" title="M402 pencil guts" width="300" height="225" class="size-medium wp-image-155" /></a><p class="wp-caption-text">M402 pencil guts</p></div><br />
You can then push the inner sleeve of the pencil out through the top of the pencil.  The inner body, clip and clicker top will come out of the pencil as a unit.<br />
Similarly, you can push the inner sleeve body out of the F701.  Now comes the exciting part (I&#8217;m easily entertained).  Slide the M402 inner pencil body into the top of the F701 pen outer body.  Slide the M402 pencil lead reservoir into the business end of the F701.  Screw it together with only finger pressure.  Don&#8217;t get too rambunctious. Now screw the M402 pencil nib on the end.  Voila!  You now have a 701 series pen and pencil set that look like this:<br />
<div id="attachment_161" class="wp-caption alignnone" style="width: 235px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0040.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0040-225x300.jpg" alt="Zebra 701 pen/pencil set" title="Zebra 701 pen/pencil set" width="225" height="300" class="size-medium wp-image-161" /></a><p class="wp-caption-text">Zebra 701 pen/pencil set</p></div><br />
As a bonus, the F701 has a clean body, and the 402 set has a clean clip.  The merger of the two is an all metal set with no markings at all.<br />
Here&#8217;s a picture of what I did with the leftover scrap.<br />
<div id="attachment_163" class="wp-caption alignnone" style="width: 310px"><a href="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0041.jpg"><img src="http://kirk.webfinish.com/wp-content/uploads/2011/01/IMG_0041-300x225.jpg" alt="Frankenpen" title="Frankenpen" width="300" height="225" class="size-medium wp-image-163" /></a><p class="wp-caption-text">Frankenpen</p></div><br />
Notice the plastic top and both the clip and the body of the pen are marked.  Neither of which is correct, since I stuck the F402 pen refill into the M402 body with the F701 clicker.  A perfect example of how *not* to do it.</p>
<p>References: <a href="http://forum.multitool.org/index.php?topic=13351.0">How to mod a Zebra 701 into a 701 space pen</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kirk.webfinish.com/2011/01/zebra-f701-pen-and-m701-pencil-set-with-serious-mods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

