snipt

Ctrl+h for KB shortcuts

Bash

Expand a symlink

ruby -e 'puts File.expand_path(File.readlink(ARGV.first), File.dirname(ARGV.first))' -- /tmp
https://snipt.net/embed/9052e3a2b805d38ebf716aab47bc7f4e/
/raw/9052e3a2b805d38ebf716aab47bc7f4e/
9052e3a2b805d38ebf716aab47bc7f4e
bash
Bash
1
2019-07-17T16:28:09
True
False
False
Jan 03, 2013 at 11:31 PM
/api/public/snipt/52745/
expand-a-symlink
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ruby -e <span class="s1">&#39;puts File.expand_path(File.readlink(ARGV.first), File.dirname(ARGV.first))&#39;</span> -- /tmp </span></pre></div> </td></tr></table>

Bash

Get Mac idle time in milliseconds

ioreg -c IOHIDSystem | grep HIDIdleTime | head -1 | sed 's/[^0-9]//g; s,$,/1000000,' | bc
https://snipt.net/embed/4c5e329e8f34ed3f7c0209a4ae0428b3/
/raw/4c5e329e8f34ed3f7c0209a4ae0428b3/
4c5e329e8f34ed3f7c0209a4ae0428b3
bash
Bash
1
2019-07-19T10:23:25
True
False
False
Dec 16, 2012 at 08:24 PM
/api/public/snipt/51926/
get-mac-idle-time-in-milliseconds
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ioreg -c IOHIDSystem <span class="p">|</span> grep HIDIdleTime <span class="p">|</span> head -1 <span class="p">|</span> sed <span class="s1">&#39;s/[^0-9]//g; s,$,/1000000,&#39;</span> <span class="p">|</span> bc </span></pre></div> </td></tr></table>
cli, mac

CoffeeScript

RegExp_escape

# http://xkr.us/js/regexregex
RegExp_escape = (str) -> str.replace(/[\\\^\$*+[\]?{}.=!:(|)]/g, "\\$&")
https://snipt.net/embed/3e394a878c40720181f8c83cea7fbd01/
/raw/3e394a878c40720181f8c83cea7fbd01/
3e394a878c40720181f8c83cea7fbd01
coffee-script
CoffeeScript
3
2019-07-17T15:53:06
True
False
False
Aug 14, 2012 at 03:54 AM
/api/public/snipt/45657/
regexp_escape
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># http://xkr.us/js/regexregex</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">RegExp_escape = </span><span class="nf">(str) -&gt;</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/[\\\^\$*+[\]?{}.=!:(|)]/g</span><span class="p">,</span> <span class="s">&quot;\\$&amp;&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
regexp