tag:blogger.com,1999:blog-52368046480001830672024-02-08T10:06:53.809-08:00oh, unixhow did I do that thing again?markhttp://www.blogger.com/profile/16857708549339482907noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5236804648000183067.post-14867004929238528692011-06-27T07:22:00.000-07:002011-06-27T07:22:33.340-07:00Cat to or from clipboard in TerminalOn a Mac, <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">man pbcopy</span> or <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">pbpaste</span> to see how to redirect into or out of your pasteboard/clipboard. With pbpaste, <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">-Prefer txt</span> can be useful to ensure ascii output.<br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">cat file.txt | pbcopy</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">pbpaste -Prefer txt > out.txt</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">Yay.</span>markhttp://www.blogger.com/profile/16857708549339482907noreply@blogger.com0tag:blogger.com,1999:blog-5236804648000183067.post-3914892538363991762011-06-21T15:10:00.000-07:002011-06-27T07:07:34.103-07:00Rotate tablet PC screen with a single button in Ubuntu 11.04Someone asked me for help on tablet screen rotation in Ubuntu for an older (2006) Lenovo X60 tablet PC - in particular, the desire was to make it as simple as possible to flip the screen 180 degrees since on this model, for right-handers, a flipped screen is more comfortable ergonomically for....tableting. Simplicity suggested a big noticeable blue button on the Unity 11.04 Launcher (the slide out bar on the left). Being new to Unity myself, there were a couple of quirks to figure out.<br />
<br />
My goal was to add a button to the launcher that would fire off a shell script. The script relies on xrandr (for screen rotation) and xsetwacom (for the stylus to map correctly to the rotated screen). They're easy to use after some manpage-skimming and they don't require elevated privileges.<br />
<br />
<script src="https://gist.github.com/1038968.js?file=screen-rotate.sh">
</script><br />
Now, how to add it to the Unity launcher bar? Either you can create a .desktop file from scratch or you can use the menu option for creating a launcher, and repurpose the .desktop to point to your script. Here's the one I used, which also points to a serviceable picture of a generic monitor icon, courtesy of Gnome.<br />
<script src="https://gist.github.com/1039022.js?file=screen-rotate.desktop">
</script><br />
After dragging it to the launcher and a re-login, the button does the intended trick.<br />
<br />
And here are a couple of <a href="http://ubuntuforums.org/showthread.php?t=1675299">useful</a> <a href="http://ubuntuforums.org/showthread.php?t=1700605">links</a> to ubuntuforums.org posts that told me everything I needed to know to rush out the above tidbits.markhttp://www.blogger.com/profile/16857708549339482907noreply@blogger.com0tag:blogger.com,1999:blog-5236804648000183067.post-9658591360138119162011-06-02T16:36:00.000-07:002011-06-02T16:43:59.067-07:00Keeping your idle ssh connection alive (the wrong way)Need to keep an ssh connection alive? Maybe you're doing it wrong - use <a href="http://en.wikipedia.org/wiki/Nohup">nohup</a>. Can't? Got some weird corner case that needs a living ssh connection with some process doing something in the foreground? You could always use expect/pexpect. But that's too much trouble! This python script is a quick and dirty way of doing it wrong:<br />
<span class="Apple-style-span" style="color: #ce00a5; font-family: Menlo; font-size: 11px;">import</span><span class="Apple-style-span" style="color: #ce00a5; font-family: Menlo; font-size: 11px;"><span class="s1" style="color: black;"> time</span></span><br />
<div class="p1" style="color: #ce00a5; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">import<span class="s1" style="color: black;"> sys</span></div><div class="p1" style="color: #ce00a5; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s1" style="color: black;"><br />
</span></div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s2" style="color: #ce00a5;">def</span> infinite():</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> i = <span class="s3" style="color: #3800e2;">0</span></div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">while</span> <span class="s3" style="color: #3800e2;">1</span>:</div><div class="p4" style="color: #e50000; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s1" style="color: black;"> </span><span class="s2" style="color: #ce00a5;">print</span><span class="s1" style="color: black;"> </span>"been asleep for "<span class="s1" style="color: black;">, i ,</span>"hours"</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> time.sleep(<span class="s3" style="color: #3800e2;">60</span> * <span class="s3" style="color: #3800e2;">60</span>)</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> i += <span class="s3" style="color: #3800e2;">1</span></div><div class="p2" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px;"><br />
</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s2" style="color: #ce00a5;">def</span> sleeper(minutes):</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">print</span> time.strftime(<span class="s4" style="color: #e50000;">"%a, %d %b %Y %I:%M:%S +0000"</span>, time.localtime())</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> time.sleep(minutes * <span class="s3" style="color: #3800e2;">60</span>)</div><div class="p5" style="color: #3800e2; font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s1" style="color: black;"> </span><span class="s2" style="color: #ce00a5;">print</span><span class="s1" style="color: black;"> </span>'awaking'</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">print</span> time.strftime(<span class="s4" style="color: #e50000;">"%a, %d %b %Y %I:%M:%S +0000"</span>, time.localtime())</div><div class="p2" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px;"><br />
</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s2" style="color: #ce00a5;">def</span> main():</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">if</span> len(sys.argv) != <span class="s3" style="color: #3800e2;">2</span>:</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">print</span> <span class="s4" style="color: #e50000;">"fail!"</span></div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">return</span></div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">if</span> sys.argv[<span class="s3" style="color: #3800e2;">1</span>] == <span class="s4" style="color: #e50000;">"infinite"</span>:</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> infinite()</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> <span class="s2" style="color: #ce00a5;">else</span>:</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> sleeper(int(sys.argv[<span class="s3" style="color: #3800e2;">1</span>]))</div><div class="p2" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px;"><br />
</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="s2" style="color: #ce00a5;">if</span> __name__ ==<span class="s4" style="color: #e50000;">"__main__"</span>:</div><div class="p3" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> main()</div><div class="p2" style="font: normal normal normal 11px/normal Menlo; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-height: 13px;"><br />
</div><div class="p2">Usage:</div><div class="p2"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">python keepawake.py 60 </span></div><div class="p2"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"></span>Sleeps for 60 minutes</div><div class="p2"><span class="Apple-style-span" style="font-family: Times; font-size: small;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">python keepawake.py infinite </span></span></div><div class="p2">sleeps until you Ctrl+C<br />
<br />
<span class="Apple-style-span" style="font-family: Times; font-size: small;"></span>If you're using this often (why?! You're doing it wrong!) then of course just throw in an alias within your .bashrc:</div><div class="p2"><span class="Apple-style-span" style="font-size: small;"></span></div><div class="p2"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">alias keepawake='python ~/path/to/keepawake.py'</span></span></div><div><br />
And now you can call:<br />
</div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">keepawake 60</span></span></div><div><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">keepawake infinite</span></span></div><div>whenever your heart desires.</div>markhttp://www.blogger.com/profile/16857708549339482907noreply@blogger.com0tag:blogger.com,1999:blog-5236804648000183067.post-19995792804435874692011-06-02T16:13:00.000-07:002011-06-27T07:32:18.141-07:00Get colors from Terminal, and pasting into vim from other programsIn seeking an answer to copying terminal output with ANSI-style colors, thanks goes to <a href="http://superuser.com/questions/229022/copy-colored-output-from-mac-os-x-terminal">this</a> question. I wanted to get colored output from Mac OS X's Terminal, and the easiest way was to print to a pdf and copy from there.<br />
<br />
Also, here's the right way to paste into vim from an external source (such as a <a href="http://ohunix.blogspot.com/2011/06/usable-parenthesis-matching-in-vim.html">gist</a>) because I seem to forget this (since I'm usually pasting from vim into vim). To avoid vim's auto-indenting or auto-commenting as the lines are written from the pastebuffer into vim, to enter paste mode just<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">:set paste</span><br />
and then, back in insert mode, Ctrl+v or Command+v or whatever suits your fancy. Once you're done,<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">:set nopaste</span><br />
<span class="Apple-style-span" style="font-family: inherit;">You've now sidestepped all that pesky smart indentation/commenting.</span>markhttp://www.blogger.com/profile/16857708549339482907noreply@blogger.com0tag:blogger.com,1999:blog-5236804648000183067.post-45680778809421720512011-06-02T15:40:00.000-07:002011-06-27T07:23:19.329-07:00Usable parenthesis matching in vimI'll post my messy hodgepodge vim configuration below but the only part worth highlighting (no pun intended) is the following trick for making vim not do terribly confusing parenthesis matching:<br />
<br />
<span class="Apple-style-span" style="color: #00c700; font-family: Monaco; font-size: 12px;"><span class="s2" style="color: #acb200;"> hi </span><span class="s3" style="color: black;">MatchParen </span>cterm<span class="s3" style="color: black;">=</span><span class="s4" style="color: #e900d8;">bold </span>ctermbg<span class="s3" style="color: black;">=</span><span class="s4" style="color: #e900d8;">none </span>ctermfg<span class="s3" style="color: black;">=red</span></span><br />
<br />
Serviceable explanation <a href="http://design.liberta.co.za/articles/customizing-disabling-vim-matching-parenthesis-highlighting/">here</a>. It's pretty self explanatory though: this changes the foreground (and background if you so choose - yellow is serviceable) of the matched parenthesis to something a little more distinctive so you don't lose track of where your cursor is. Default matching always makes me confused whenever I'm navigating around, especially in parenthesis-heavy code. And I guess it's nice that you can just use color names like white or green, even though that bugs me, because I have no idea if it will support, say, fuchsia... or glaucous. (I think it probably just supports basic 256-color palette names, but feel free to comment with a link to the specification or vim source)<br />
<br />
And for posterity, my whole vimrc, with some comments mixed in:<br />
<script src="https://gist.github.com/1048929.js?file=gistfile1.vim"></script><br />
More vim tips to come in the next post.markhttp://www.blogger.com/profile/16857708549339482907noreply@blogger.com0