Sorry

This feed does not validate.

In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.

Source: http://www.perturb.org/atom.php

  1. <br />
  2. <b>Warning</b>:  Undefined variable $out in <b>/home/bakers/html/perturb.class.php</b> on line <b>1197</b><br />
  3. <br />
  4. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  5. <br />
  6. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  7. <br />
  8. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  9. <br />
  10. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  11. <br />
  12. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  13. <br />
  14. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  15. <br />
  16. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  17. <br />
  18. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  19. <br />
  20. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  21. <br />
  22. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  23. <br />
  24. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  25. <br />
  26. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  27. <br />
  28. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  29. <br />
  30. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  31. <br />
  32. <b>Warning</b>:  Undefined variable $summary in <b>/home/bakers/html/perturb.class.php</b> on line <b>1236</b><br />
  33. <?xml version="1.0" encoding="iso-8859-1"?>
  34. <?xml-stylesheet type="text/css" href="/css/atom-browser.css" ?>
  35. <feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en"> <title>Perturb.org - Scott's Geek Blog</title>
  36. <modified>2025-04-02T15:59:57-07:00</modified> <link rel="alternate" type="text/html" href="http://www.perturb.org" /> <tagline>Geek blog</tagline>
  37. <id>tag:www.perturb.org,2025://04</id>
  38. <generator>Perturb ATOM v0.1</generator>
  39. <entry xmlns="http://purl.org/atom/ns#">
  40. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1424/" />
  41. <title mode="escaped">Vim: Insert a line of characters</title>
  42. <modified>2025-04-01T00:00:00-07:00</modified>
  43. <issued>2025-04-01T00:00:00-07:00</issued>
  44. <created>2025-04-01T00:00:00-07:00</created>
  45. <id>http://www.perturb.org/display/entry/1424/</id>
  46. <summary type="text/plain"></summary>
  47. <author>
  48. <name>Scott Baker</name>
  49. <url>http://www.perturb.org/</url>
  50. <email>scott@perturb.org</email>
  51. </author>
  52. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  53. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  54.  
  55. I need an 80 character divider of text in Vim. I can never remember the sequence so I'm writing it down: <br />
  56. <br />
  57. ``` <br />
  58. 80i/<ESC> <br />
  59. ``` <br />
  60. <br />
  61. Will generate: <br />
  62. <br />
  63. ```text <br />
  64. //////////////////////////////////////////////////////////////////////////////// <br />
  65. ```
  66. ]]>
  67. </content>
  68. </entry>
  69. <entry xmlns="http://purl.org/atom/ns#">
  70. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1423/" />
  71. <title mode="escaped">Comparing 32bit and 64bit performance on low end micro-controllers</title>
  72. <modified>2025-03-05T13:47:09-08:00</modified>
  73. <issued>2025-03-05T13:47:09-08:00</issued>
  74. <created>2025-03-05T13:47:09-08:00</created>
  75. <id>http://www.perturb.org/display/entry/1423/</id>
  76. <summary type="text/plain"></summary>
  77. <author>
  78. <name>Scott Baker</name>
  79. <url>http://www.perturb.org/</url>
  80. <email>scott@perturb.org</email>
  81. </author>
  82. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  83. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  84.  
  85. Testing 32bit vs 64bit PRNGs on a 32bit ESP32-C3 [I'm seeing](https://gist.github.com/scottchiefbaker/e4c87de8d6c1ad4a33b1ffe5a3ce707f): <br />
  86. <br />
  87. | PRNG          | Iterations per second | Output Bits | Bytes per second | <br />
  88. | ------------- | --------------------- | ----------- | ---------------- | <br />
  89. | pcg32         | 487802                | 32          | **1951266.7 b/s**| <br />
  90. | xoroshiro64** | **516023**            | 32          | 2050966.7 b/s    | <br />
  91. | xoshiro256+   | 487808                | 64          | **3878726.7 b/s**| <br />
  92. | xoshiro512++  | 441735                | 64          | 3514373.3 b/s    | <br />
  93. | splitmix64    | 462290                | 64          | 3677033.3 b/s    | <br />
  94. | pcg64         | **416297**            | 64          | 3313060.0 b/s    | <br />
  95. <br />
  96. Very little difference on PRNGs that use 64bit operations vs 32bit operations. Even on limited hardware like this it makes sense to use a 64bit PRNG because you get more bytes per cycle.
  97. ]]>
  98. </content>
  99. </entry>
  100. <entry xmlns="http://purl.org/atom/ns#">
  101. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1422/" />
  102. <title mode="escaped">Vim: Convert your syntax highlighted text into HTML</title>
  103. <modified>2025-02-26T00:00:00-08:00</modified>
  104. <issued>2025-02-26T00:00:00-08:00</issued>
  105. <created>2025-02-26T00:00:00-08:00</created>
  106. <id>http://www.perturb.org/display/entry/1422/</id>
  107. <summary type="text/plain"></summary>
  108. <author>
  109. <name>Scott Baker</name>
  110. <url>http://www.perturb.org/</url>
  111. <email>scott@perturb.org</email>
  112. </author>
  113. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  114. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  115.  
  116. Vim is my code editor of choice as it has great features, excellent syntax highlighting, and a robust plug-in infrastructure. I'm very used to look and feel of Vim. If you want to share some of your code online, converting things to HTML can be problematic. Luckily Vim has a built in code to HTML converter: <br />
  117. <br />
  118. ``` <br />
  119. :TOhtml <br />
  120. ``` <br />
  121. <br />
  122. Simply run the `:TOhtml` command in an open text file and your buffer will be redrawn in HTML which you can then save. Here is a quick sample of my pcg32.pl script [converted to HTML](https://www.perturb.org/code/pcg32.pl.html).
  123. ]]>
  124. </content>
  125. </entry>
  126. <entry xmlns="http://purl.org/atom/ns#">
  127. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1421/" />
  128. <title mode="escaped">What kind of number makes a good seed for a PRNG?</title>
  129. <modified>2025-02-20T00:00:00-08:00</modified>
  130. <issued>2025-02-20T00:00:00-08:00</issued>
  131. <created>2025-02-20T00:00:00-08:00</created>
  132. <id>http://www.perturb.org/display/entry/1421/</id>
  133. <summary type="text/plain"></summary>
  134. <author>
  135. <name>Scott Baker</name>
  136. <url>http://www.perturb.org/</url>
  137. <email>scott@perturb.org</email>
  138. </author>
  139. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  140. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  141.  
  142. [Pseudo-random number generators](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) use complex math to generate random numbers on your computer. These random numbers are used for all sorts of things: simulations, fractals, games, art, and even math experiments. Computers can **only** do math, which makes generating a random number difficult.  <br />
  143. <br />
  144. PRNGs need a "seed" number to kick off the math that generates sequences of random numbers. Some PRNGs require a 32bit seed, and some require a 64bit seed. Some PRNGs require one seed, and some require four (or more). It is important to know what type of seed your PRNG needs. <br />
  145. <br />
  146. A 32bit number is between 0 and 4.2 billion and a 64bit number is between 0 and 18.4 quintillion. The larger a number is, the more bits are required to store it, and the better a seed it will make. The closer your seed is to the upper end of the number range the better. As a general rule a good seed will be a decimal number with 18 or 19 digits. <br />
  147. <br />
  148. `12` is a small number and **not** a good seed, `4611686018427387906` is a big number but still not a great seed. Seeds should **not** have large sections of zero/one bits. This is why small numbers do not make good seeds. Bits can be visualized by printing the number in binary: <br />
  149. <br />
  150. ```bash <br />
  151. # Horrible <br />
  152. $ perl -E 'printf("%064b\n", 4611686018427387906)' <br />
  153. 0100000000000000000000000000000000000000000000000000000000000010 <br />
  154. <br />
  155. # Bad <br />
  156. $ perl -E 'printf("%064b\n", 17770)' <br />
  157. 0000000000000000000000000000000000000000000000000100010101101010 <br />
  158. <br />
  159. # Poor <br />
  160. $ perl -E 'printf("%064b\n", 2850756010)' <br />
  161. 0000000000000000000000000000000010101001111010110001010110101010 <br />
  162. <br />
  163. # Good <br />
  164. $ perl -E 'printf("%064b\n", 11337502976607798025)' <br />
  165. 1001110101010110111001101110001101111000101001000100001100001001 <br />
  166. ``` <br />
  167. <br />
  168. Good seeds should have a _roughly_ even mix of zero and one bits. `9223372036854775808` is a large number and looks promising but it has 63 zeros, and only a single one bit. You can visualize the quality of your seed with [seed_quality.pl](https://www.perturb.org/code/seed_quality.pl). Quality above 75% should make for good seed numbers. <br />
  169. <br />
  170. Seeds should **not** be predictable. Do not use dates, times, or phone numbers as they are potentially guessable. Combinations of numbers can be good sources. Process PID, UID, unixtime are good potential sources _if_ they are combined together in a non-predictable way. PID multiplied by UID multiplied by Unixtime is an example of combining values. Memory locations of variables, especially if [ASLR](https://en.wikipedia.org/wiki/Address_space_layout_randomization) is in use is a potentially good source as well. <br />
  171. <br />
  172. Hashing numbers, strings, or combinations of numbers can be a good way to generate seeds. Hashing a value with [Komihash](https://github.com/scottchiefbaker/perl-Crypt-Komihash) or [xxHash](https://metacpan.org/pod/Digest::xxHash) will generate a suitable 64bit number. Hashing a value with [SHA256](https://metacpan.org/pod/Digest::SHA) will generate a 256bit value which can be [split](https://www.perturb.org/display/1415_Perl_Using_sha256_to_hash_strings_into_integers.html) into four 64bit values. Hashing functions also do a good job of ensuring the bits are mixed well and do not include large repeating sections. <br />
  173. <br />
  174. The best source of seed numbers is directly from your OS. On Linux this is `/dev/urandom` and on Windows you can interface with the `RtlGenRandom` API. These are carefully curated sources of _true_ randomness, but they can be slow-ish. Using them as a source for a fast PRNG is best practice. <br />
  175. <br />
  176. ```perl <br />
  177. sub get_64bit_seed { <br />
  178.    open my $urandom, '<:raw', '/dev/urandom' or croak("Couldn't open /dev/urandom: $!"); <br />
  179.    sysread($urandom, my $buf, 8) or croak("Couldn't read from csprng: $!"); <br />
  180. <br />
  181.    return unpack("Q*", $buf); <br />
  182. } <br />
  183. ```
  184. ]]>
  185. </content>
  186. </entry>
  187. <entry xmlns="http://purl.org/atom/ns#">
  188. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1420/" />
  189. <title mode="escaped">Perl: Multiply-Shift Hash</title>
  190. <modified>2025-01-27T00:00:00-08:00</modified>
  191. <issued>2025-01-27T00:00:00-08:00</issued>
  192. <created>2025-01-27T00:00:00-08:00</created>
  193. <id>http://www.perturb.org/display/entry/1420/</id>
  194. <summary type="text/plain"></summary>
  195. <author>
  196. <name>Scott Baker</name>
  197. <url>http://www.perturb.org/</url>
  198. <email>scott@perturb.org</email>
  199. </author>
  200. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  201. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  202.  
  203. I've been using the multiply-shift hash lately and have had good results. It's simple, fast, and well tested.  <br />
  204. <br />
  205. ```c <br />
  206. // Multiply-Shift Hash <br />
  207. static uint64_t hash_msh(uint64_t x) { <br />
  208.    uint64_t prime = 0x9e3779b97f4a7c15; // A large prime constant <br />
  209.    x ^= (x >> 30); <br />
  210.    x *= prime; <br />
  211.    x ^= (x >> 27); <br />
  212.    x *= prime; <br />
  213.    x ^= (x >> 31); <br />
  214.    return x; <br />
  215. } <br />
  216. ``` <br />
  217. <br />
  218. Whenever I find interesting code like this I like to try and implement it in Perl: <br />
  219. <br />
  220. ```perl <br />
  221. sub hash_msh { <br />
  222.    my $x     = $_[0]; <br />
  223.    my $prime = 11400714819323198485; <br />
  224.     <br />
  225.    $x ^= ($x >> 30); <br />
  226.    $x = multiply_uv($x, $prime); <br />
  227.    $x ^= ($x >> 27); <br />
  228.    $x = multiply_uv($x, $prime); <br />
  229.    $x ^= ($x >> 31); <br />
  230. <br />
  231.    return $x; <br />
  232. } <br />
  233. <br />
  234. # Perl converts numbers larger than 2^64 - 1 to floating point so <br />
  235. # we 'use integer' to force integer math which retains any overflow. <br />
  236. sub multiply_uv { <br />
  237.    my ($one, $two) = @_; <br />
  238. <br />
  239.    use integer; <br />
  240.    my $ret = $one * $two; <br />
  241.    no integer; <br />
  242. <br />
  243.    # Convert signed IV to unsinged UV <br />
  244.    if ($ret < 0) { <br />
  245.        $ret += 18446744073709551615; <br />
  246.        $ret += 1; <br />
  247.    } <br />
  248. <br />
  249.    return $ret; <br />
  250. } <br />
  251. ```
  252. ]]>
  253. </content>
  254. </entry>
  255. <entry xmlns="http://purl.org/atom/ns#">
  256. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1419/" />
  257. <title mode="escaped">Perl: Calculate number of bits needed to store a number</title>
  258. <modified>2025-01-27T00:00:00-08:00</modified>
  259. <issued>2025-01-27T00:00:00-08:00</issued>
  260. <created>2025-01-27T00:00:00-08:00</created>
  261. <id>http://www.perturb.org/display/entry/1419/</id>
  262. <summary type="text/plain"></summary>
  263. <author>
  264. <name>Scott Baker</name>
  265. <url>http://www.perturb.org/</url>
  266. <email>scott@perturb.org</email>
  267. </author>
  268. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  269. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  270.  
  271. Quick Perl function to calculate the number of bits required to store a given number. <br />
  272. <br />
  273. ```perl <br />
  274. sub bits_required { <br />
  275.    my ($n) = @_; <br />
  276.     <br />
  277.    # Handle special case for 0 <br />
  278.    return 0 if $n == 0; <br />
  279. <br />
  280.    # Use logarithm to calculate the number of bits <br />
  281.    my $bits = int(log($n) / log(2)) + 1; <br />
  282.    return $bits; <br />
  283. } <br />
  284. ```
  285. ]]>
  286. </content>
  287. </entry>
  288. <entry xmlns="http://purl.org/atom/ns#">
  289. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1418/" />
  290. <title mode="escaped">Implmenting PRNGs in Perl</title>
  291. <modified>2025-01-25T00:00:00-08:00</modified>
  292. <issued>2025-01-25T00:00:00-08:00</issued>
  293. <created>2025-01-25T00:00:00-08:00</created>
  294. <id>http://www.perturb.org/display/entry/1418/</id>
  295. <summary type="text/plain"></summary>
  296. <author>
  297. <name>Scott Baker</name>
  298. <url>http://www.perturb.org/</url>
  299. <email>scott@perturb.org</email>
  300. </author>
  301. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  302. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  303.  
  304. I'm a big fan of the [PCG32 PRNG](https://www.pcg-random.org/download.html). It's simple, fast, and well documented. As is usually the case when I find interesting code I try and find a way to implement it in Perl. PCG32 poses an interesting problem when one tries to implement it in Perl because all the math is performed using **unsigned** integers and overflow. Most PRNGs use large numbers and overflow to work, that's their secret sauce. <br />
  305. <br />
  306. Perl does not have a native unsigned type so I had to learn the guts of how Perl does math so I could emulate it. I ended up coming up with two different implementations, a native Perl implementation, and a version that uses `Math::Int64`. Surprisingly the native version was *significantly* faster.  <br />
  307. <br />
  308. Both implementations with detailed comments are available in [pcg32.pl](https://www.perturb.org/code/syntax_highlight.php?file=pcg32.pl) if you're interested in learning more about how to do integer style math in Perl.  <br />
  309. <br />
  310. As a bonus I also ported the [xoshiro256 family](https://www.perturb.org/code/syntax_highlight.php?file=xoshiro256.pl) into Perl. [Splitmix64](https://www.perturb.org/code/syntax_highlight.php?file=splitmix64.pl) ended up being a little more complicated to port, but I got it as well.
  311. ]]>
  312. </content>
  313. </entry>
  314. <entry xmlns="http://purl.org/atom/ns#">
  315. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1417/" />
  316. <title mode="escaped">C/C++: List all #define macros</title>
  317. <modified>2025-01-22T00:00:00-08:00</modified>
  318. <issued>2025-01-22T00:00:00-08:00</issued>
  319. <created>2025-01-22T00:00:00-08:00</created>
  320. <id>http://www.perturb.org/display/entry/1417/</id>
  321. <summary type="text/plain"></summary>
  322. <author>
  323. <name>Scott Baker</name>
  324. <url>http://www.perturb.org/</url>
  325. <email>scott@perturb.org</email>
  326. </author>
  327. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  328. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  329.  
  330. I need to target a specific platform with some code I'm writing. You can list **all** of the `#define` macros on a given platform with these commands: <br />
  331. <br />
  332. ``` <br />
  333. gcc -dM -E - < /dev/null <br />
  334. ``` <br />
  335. <br />
  336. ``` <br />
  337. clang -dM -E - < /dev/null <br />
  338. ``` <br />
  339. <br />
  340. In this big list of macros you should find something to help you target a given platform.
  341. ]]>
  342. </content>
  343. </entry>
  344. <entry xmlns="http://purl.org/atom/ns#">
  345. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1416/" />
  346. <title mode="escaped">FFMPEG: Limit the output to only the encoding stats for quieter scripting</title>
  347. <modified>2025-01-21T00:00:00-08:00</modified>
  348. <issued>2025-01-21T00:00:00-08:00</issued>
  349. <created>2025-01-21T00:00:00-08:00</created>
  350. <id>http://www.perturb.org/display/entry/1416/</id>
  351. <summary type="text/plain"></summary>
  352. <author>
  353. <name>Scott Baker</name>
  354. <url>http://www.perturb.org/</url>
  355. <email>scott@perturb.org</email>
  356. </author>
  357. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  358. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  359.  
  360. FFMPEG is a great tool, but it is very chatty. If you want to encode a file you'll get about 40 lines of headers and track information, most of which you probably will not read. For scripting purposes you probably **only** want to see the statistics. If you start FFMPEG, hide the banner, and set the loglevel low you can output only the stats you need <br />
  361. <br />
  362. ```bash <br />
  363. ffmpeg -y -hide_banner -loglevel quiet -stats ... <br />
  364. ```
  365. ]]>
  366. </content>
  367. </entry>
  368. <entry xmlns="http://purl.org/atom/ns#">
  369. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1415/" />
  370. <title mode="escaped">Perl: Using sha256 to hash strings into integers</title>
  371. <modified>2025-01-20T00:00:00-08:00</modified>
  372. <issued>2025-01-20T00:00:00-08:00</issued>
  373. <created>2025-01-20T00:00:00-08:00</created>
  374. <id>http://www.perturb.org/display/entry/1415/</id>
  375. <summary type="text/plain"></summary>
  376. <author>
  377. <name>Scott Baker</name>
  378. <url>http://www.perturb.org/</url>
  379. <email>scott@perturb.org</email>
  380. </author>
  381. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  382. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  383.  
  384. I need 64bit integers to seed some PRNG work I'm doing. I found out that you can easily create four 64bit numbers from any string by using SHA256. <br />
  385. <br />
  386. ``` <br />
  387. use Digest::SHA; <br />
  388. <br />
  389. my $input = $ARGV[0] || int(rand() * 1000000); <br />
  390. <br />
  391. # Get raw bytes and convert to an array of uint64_t <br />
  392. my $hash = Digest::SHA::sha256($input); <br />
  393. my @nums = unpack("Q*", $hash); <br />
  394. <br />
  395. print "SHA256 Hashing '$input' to: " . join(", ", @nums) . "\n"; <br />
  396. ``` <br />
  397. <br />
  398. **Note:** We are using `sha256` here, not `sha256_hex` because we need raw bytes to convert to integers with `unpack`.
  399. ]]>
  400. </content>
  401. </entry>
  402. <entry xmlns="http://purl.org/atom/ns#">
  403. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1414/" />
  404. <title mode="escaped">Komihash is pretty amazing and simple hashing algorithm</title>
  405. <modified>2025-01-17T00:00:00-08:00</modified>
  406. <issued>2025-01-17T00:00:00-08:00</issued>
  407. <created>2025-01-17T00:00:00-08:00</created>
  408. <id>http://www.perturb.org/display/entry/1414/</id>
  409. <summary type="text/plain"></summary>
  410. <author>
  411. <name>Scott Baker</name>
  412. <url>http://www.perturb.org/</url>
  413. <email>scott@perturb.org</email>
  414. </author>
  415. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  416. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  417.  
  418. I need a simple way to hash strings into 64bit integers so I started [some research](https://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions). Initially I was focusing on [xxHash](https://github.com/Cyan4973/xxHash) but it's slightly harder to implement than other newer hashes. I ended up landing on the amazing [Komihash](https://github.com/avaneev/komihash) which bills itself as: "a very fast 64-bit hash function, mainly designed for hash-table, hash-map, and bloom-filter uses". <br />
  419. <br />
  420. Komihash is available as a single `Komihash.h` file and is _extremely easy_ to implement into existing code. <br />
  421. <br />
  422. ```c <br />
  423. #include <stdio.h> <br />
  424. #include <stdlib.h> <br />
  425. #include "komihash.h" <br />
  426. <br />
  427. int main(int argc, char *argv[]) { <br />
  428.    int seed        = 0; <br />
  429.    const char *buf = "Hello world"; <br />
  430. <br />
  431.    uint64_t hash_num = komihash(buf, strlen(buf), seed); <br />
  432. <br />
  433.    printf("Komihash: %s = %llu\n", buf, hash_num); // 3745467240760726046 <br />
  434. } <br />
  435. ``` <br />
  436. <br />
  437. As a bonus it also comes with a PRNG which is equally simple to implement: <br />
  438. <br />
  439. ```c <br />
  440. #include <stdio.h> <br />
  441. #include <stdlib.h> <br />
  442. #include <time.h> <br />
  443. #include "komihash.h" <br />
  444. <br />
  445. int main(int argc, char *argv[]) { <br />
  446. uint64_t seed1 = time(NULL) * 0x61c8864680b583ebull; // hash64 <br />
  447. uint64_t seed2 = seed1      * 0x61c8864680b583ebull; // hash64 <br />
  448. <br />
  449. for (int i = 0; i < 5; i++) { <br />
  450. uint64_t rand64 = komirand(&seed1, &seed2); <br />
  451. printf("Komirand: %llu\n", rand64); <br />
  452. } <br />
  453. } <br />
  454. ``` <br />
  455. <br />
  456. In fact, I liked it so much I ported it to Perl and called it [Crypt::Komihash](https://github.com/scottchiefbaker/perl-Crypt-Komihash/).
  457. ]]>
  458. </content>
  459. </entry>
  460. <entry xmlns="http://purl.org/atom/ns#">
  461. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1413/" />
  462. <title mode="escaped">Perl: Warning about non-portable numbers</title>
  463. <modified>2025-01-16T00:00:00-08:00</modified>
  464. <issued>2025-01-16T00:00:00-08:00</issued>
  465. <created>2025-01-16T00:00:00-08:00</created>
  466. <id>http://www.perturb.org/display/entry/1413/</id>
  467. <summary type="text/plain"></summary>
  468. <author>
  469. <name>Scott Baker</name>
  470. <url>http://www.perturb.org/</url>
  471. <email>scott@perturb.org</email>
  472. </author>
  473. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  474. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  475.  
  476. If you get a Perl warning about non-portable numbers like this: <br />
  477. <br />
  478. ```bash <br />
  479. Hexadecimal number > 0xffffffff non-portable at /tmp/x.pl line 19. <br />
  480. ``` <br />
  481. <br />
  482. It means that you are using a hex number greater than 2^32. I dunno why this is a warning when everything is 64bit these days, but it is. There have been a couple of times I needed this in my code so you can disable these warnings with: <br />
  483. <br />
  484. ```perl <br />
  485. no warnings 'portable'; <br />
  486. ```
  487. ]]>
  488. </content>
  489. </entry>
  490. <entry xmlns="http://purl.org/atom/ns#">
  491. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1412/" />
  492. <title mode="escaped">Books of 2025</title>
  493. <modified>2025-01-08T00:00:00-08:00</modified>
  494. <issued>2025-01-08T00:00:00-08:00</issued>
  495. <created>2025-01-08T00:00:00-08:00</created>
  496. <id>http://www.perturb.org/display/entry/1412/</id>
  497. <summary type="text/plain"></summary>
  498. <author>
  499. <name>Scott Baker</name>
  500. <url>http://www.perturb.org/</url>
  501. <email>scott@perturb.org</email>
  502. </author>
  503. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  504. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  505.  
  506. List of books I read in 2025. Also see the list of [2024](/display/1392_Books_of_2024.html). The date indicated denotes the date I started reading the book.   <br />
  507. <br />
  508. 2025-01-06 - [Mistborn](//www.google.com/search?tbo=p&q=isbn+9781250318541) by Brandon Sanderson - 643 pages   <br />
  509. 2025-01-17 - [Ender's Game](//www.google.com/search?tbo=p&q=isbn+0812550706) by Orson Scott Card - 324 pages   <br />
  510. 2025-01-22 - [Thinner](//www.google.com/search?tbo=p&q=isbn+0451137965) by Stephen King - 318 pages   <br />
  511. 2025-01-26 - [The Dead Zone](//www.google.com/search?tbo=p&q=isbn+0670260770) by Stephen King - 426 pages   <br />
  512. 2025-02-02 - [The Neverending Story](//www.google.com/search?tbo=p&q=isbn+9780140074314) by Michael Ende - 377 pages   <br />
  513. 2025-02-08 - [The Well Of Ascension](//www.google.com/search?tbo=p&q=isbn+9781250318572) by Brandon Sanderson - 785 pages   <br />
  514. 2025-02-21 - [Skeleton Crew - The Monkey](//www.google.com/search?tbo=p&q=isbn+9780399130397) by Stephen King - 32 pages   <br />
  515. 2017-02-21 - [Speaker for the Dead](//www.google.com/search?tbo=p&q=9780812550757) by Orson Scott Card - 395 Pages   <br />
  516. 2025-02-27 - [Insomnia](//www.google.com/search?tbo=p&q=isbn+0670855030) by Stephen King - 787 pages   <br />
  517. 2025-03-11 - [Hero Of Ages](//www.google.com/search?tbo=p&q=isbn+9781250318626) by Brandon Sanderson - 752 pages   <br />
  518. 2025-03-23 - [Xenocide](//www.google.com/search?tbo=p&q=isbn+0812509250) by Orson Scott Card - 592 pages   <br />
  519. 2025-04-01 - [Tainted Cup](//www.google.com/search?tbo=p&q=isbn+9781984820709) by Robert Jackson Bennett - 410 pages   <br />
  520. <br />
  521. 2025-xx-xx - [The Sword Of Shannara](//www.google.com/search?tbo=p&q=isbn+9780345314253) by Terry Brooks - 726 pages
  522. ]]>
  523. </content>
  524. </entry>
  525. <entry xmlns="http://purl.org/atom/ns#">
  526. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1411/" />
  527. <title mode="escaped">C: Nanoseconds since Unix epoch</title>
  528. <modified>2024-12-31T00:00:00-08:00</modified>
  529. <issued>2024-12-31T00:00:00-08:00</issued>
  530. <created>2024-12-31T00:00:00-08:00</created>
  531. <id>http://www.perturb.org/display/entry/1411/</id>
  532. <summary type="text/plain"></summary>
  533. <author>
  534. <name>Scott Baker</name>
  535. <url>http://www.perturb.org/</url>
  536. <email>scott@perturb.org</email>
  537. </author>
  538. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  539. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  540.  
  541. I needed a function to use as a simple seed for `srand()`. Unixtime in nanoseconds changes very frequently and serves as a semi-decent random seed. <br />
  542. <br />
  543. ```c <br />
  544. #include <time.h> // for clock_gettime() <br />
  545. <br />
  546. // Nanoseconds since Unix epoch <br />
  547. uint64_t nanos() { <br />
  548.    struct timespec ts; <br />
  549. <br />
  550.    // int8_t ok = clock_gettime(CLOCK_MONOTONIC, &ts); // Uptime <br />
  551.    int8_t ok = clock_gettime(CLOCK_REALTIME, &ts);  // Since epoch <br />
  552. <br />
  553.    if (ok != 0) { <br />
  554.        return 0; // Return 0 on failure (you can handle this differently) <br />
  555.    } <br />
  556. <br />
  557.    // Calculate nanoseconds <br />
  558.    uint64_t ret = (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec; <br />
  559. <br />
  560.    return ret; <br />
  561. } <br />
  562. ``` <br />
  563. <br />
  564. See also: [Microseconds](/display/1409_Perl_Get_microseconds_since_Unix_epoch.html) since epoch in Perl
  565. ]]>
  566. </content>
  567. </entry>
  568. <entry xmlns="http://purl.org/atom/ns#">
  569. <link rel="alternate" type="text/html" href="http://www.perturb.org/display/entry/1410/" />
  570. <title mode="escaped">Git: Show all changes to a given file</title>
  571. <modified>2024-12-31T00:00:00-08:00</modified>
  572. <issued>2024-12-31T00:00:00-08:00</issued>
  573. <created>2024-12-31T00:00:00-08:00</created>
  574. <id>http://www.perturb.org/display/entry/1410/</id>
  575. <summary type="text/plain"></summary>
  576. <author>
  577. <name>Scott Baker</name>
  578. <url>http://www.perturb.org/</url>
  579. <email>scott@perturb.org</email>
  580. </author>
  581. <content type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.perturb.org">
  582. <![CDATA[<link rel="stylesheet" type="text/css" media="screen" href="/css/rss-feed.css" title="Default" />
  583.  
  584. If you want to view the history of all the changes you've made to a specific file in Git you can use the `log` command in Git. This will show you all the commits that touched that file, and the associated commit message.  <br />
  585. <br />
  586. ``` <br />
  587. git log README.md <br />
  588. ``` <br />
  589. <br />
  590. If you want to see a diff/patch for each commit you can run: <br />
  591. <br />
  592. ``` <br />
  593. git log --follow --patch README <br />
  594. ``` <br />
  595. <br />
  596. This can be very useful to track down when a specific piece of code went into (or was taken out of) a file. Be careful as this command only shows you the diff/patch for the file you request. If the commit contains changes to other files you will **not** see those unless you view the full commit.
  597. ]]>
  598. </content>
  599. </entry>
  600. </feed>
  601.  
Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda