The Lumber Room

"Consign them to dust and damp by way of preserving them"

Archive for the ‘compknow’ Category

Converting a data URL (aka data URI) to an image on the commandline (Mac OS X)

leave a comment »

This is trivial, but was awfully hard to find via Google Search. Eventually had to give up and actually think about it. :-)

So, a data-URI looks something like the following:

data:image/png;base64,[and a stream of base64 characters here]

The part after the comma is literally the contents of the file (image or whatever), encoded in base64, so all you need to do is run base64 --decode on that part.

For example, with the whole data URL copied to the clipboard, I can do:

pbpaste | sed -e 's#data:image/png;base64,##' | base64 --decode > out.png

to get it into a png file.

Advertisements

Written by S

Sun, 2015-09-27 at 19:58:17

Posted in compknow

Using Stellarium to make an animation / video

leave a comment »

(I don’t have a solution yet.)

I just wanted to show what the sky looks like over the course of a week.

On a Mac with Stellarium installed, I ran the following

/Applications/Stellarium.app/Contents/MacOS/stellarium --startup-script stellarium.ssc

with the following stellarium.ssc:

// -*- mode: javascript -*-
core.clear('natural');  // "atmosphere, landscape, no lines, labels or markers"
core.wait(5);
core.setObserverLocation('Ujjain, India');
core.setDate('1986-08-15T05:30:00', 'utc');
core.wait(5);
for (var i = 0; i < 2 * 24 * 7; i += 1) {
    core.setDate('+30 minutes');
    core.wait(0.5);
    core.screenshot('uj');
    core.wait(0.5);
}
core.wait(10);
core.quitStellarium();

It took a while (some 10–15 minutes) and created those 336 images in ~/Pictures/Stellarium/uj*, occupying a total size of about 550 MB. This seems a start, but Imagemagick etc. seem to choke on creating a GIF from such large data.

Giving up for now; would like to come back in future and figure out something better, that results in a smaller GIF.

Written by S

Mon, 2015-09-14 at 20:10:10

Typing Kannada on Mac OS X

with 17 comments

(Thanks to this and this.)

Turns out it’s very easy, and we can basically use the same input method (UIM) as in Linux.

  1. Get MacUIM from its website
  2. Install it.
  3. Go to System Preferences -> Language & Text -> Input Sources System Preferences -> Keyboard -> Input Sources, and turn on MacUIM. (Click + and add “MacUIM (Roman)” under English.) Tick “Show Input menu in menu bar” too. Screen Shot 2013-04-07 at 12.33.19 AM
  4. I now have three input methods: US, EasyIAST (see earlier post), and MacUIM (Roman).
  5. Go to System Preferences -> MacUIM -> General, and in Input method, choose m17n-kn-itrans
  6. Go to System Preferences -> MacUIM -> Helper, tick “Use Helper-Applet”, and in the list at the right, tick m17n-kn-itrans.
    Screen Shot 2013-04-07 at 5.45.57 PM
  7. [Just for me] I have some changes to kn-itrans.mim, to make it closer to HK (and remove nonsense like “RRi” or whatnot just to type ಋ): download this file kn-itrans.mim, and remove the pdf extension. It goes into /Library/M17NLib/share/m17n/kn-itrans.mim

Written by S

Sun, 2013-04-07 at 01:14:35

Posted in compknow

My Git personal reference

with 9 comments

Various git things I’ve had to look up from time to time.

(Always, while doing anything dangerous, have a gitk window open. Look, don’t guess. (Haven’t used gitk in a while.) And if you’re sharing your repository publicly, you can forget about most of the below.)

Git reset

What git reset <commit> does:
* Reset HEAD to the given commit
* (If not --soft) copy this new HEAD to the index
* (If --hard) copy contents of index to working dir

So, for example:
* To “undo commit”: git reset HEAD~1
This resets HEAD to HEAD~1, without copying this new HEAD to the index. So it’s as if you didn’t make the commit. You can go and commit in another branch if you want.

Copy commits from another repository

# 1. Add the other repo as a remote
git remote add other_repo_nickname <other repo's path/url>
# 2. Fetch its data. (pull = fetch + merge, so we want only fetch, not pull)
git fetch other_repo_nickname
# 3. The rest should be familiar
git cherry-pick <commit>

Note that you don’t need to specify the remote’s name for cherry-picking. Once you have fetched, all commits, even those originally from the other repo, can be identified just by hash. (If you want to refer to commit by branch, then you can identify it with “other_repo_nickname/branch_name”.)

Swap commits (reorder top two commits)

 git rebase -i HEAD~2 

and in your editor, reorder the two “pick” lines. (See here.)

Recovering commits deleted with reset --hard

In general, these are garbage-collected after 30 days (or when you run git prune or git gc), so you shouldn’t use reset --hard at least without doing a stash first.
If the garbage-collection hasn’t happened yet, get the sha1 hash of the commit with

 git reflog 

then make sure the commit is what you want with

 git show sha1 

and get the commit back with

 git cherry-pick sha1 

(or rebase or merge instead of cherry-pick, if that’s what you want.)

Squashing commits together, to keep your history clean

Use rebase. To squash the last n commits into one, do

 git rebase -i HEAD~n 

and change all “pick”s except the first one to “squash” (or “s”). See here and here.

Delete a specific commit

Use rebase -i, again.

 git rebase -i <commit>~1 

Delete the line for the commit you want deleted. See here and here.

Amend a specific older commit

This is tricky, and I don’t think I’ve seen it anywhere, especially for the case where there are branches that depend on it.
My solution: Find the first branch X that’s downstream from (= later than) it. Keep track of the whole tree downstream from X (take a screenshot if you must); you’ll need it. Checkout X, and do “rebase -i HEAD~[large enough number to cover the commit you want to amend]”. In the editor that pops up, keep all “pick” lines, changing only that one line you want to amend to “edit”. Save and close. Now git has stopped, allowing you to amend that commit. Edit the file. Do “commit –amend” (don’t forget to add all files you want included in that commit!). Do “rebase –continue”. You’re back at X now. Now for the first branch Y that was downstream from X, checkout Y, do “git rebase X”, and recurse on Y.
This doesn’t seem work (gets into rebase conflicts). Need to try again, and ask.

Written by S

Tue, 2011-11-29 at 10:06:52

Posted in compknow

Tagged with

Getting back non-monospaced font in WordPress’s HTML editor

leave a comment »

So apparently some farsighted folks over at WordPress decided recently (see screenshots) that everyone who uses the HTML editor is using it to write code, rather than simply because the unpredictable “Visual” editor sucks so much. If you use WordPress, don’t like this change and would like to go back to using more normal fonts, (you can go complain at the appropriate places, or) open either Firebug console, or in Google Chrome go to View → Developer → Developer Tools and choose the console, and type

document.getElementById('content').style.cssText += "font-family: sans-serif;"

or whatever it is that you want. Making this a Greasemonkey/Stylish/whatever extension is left for others; I just want something quick to fix this annoyance.

Monospaced is fine for code, but typical monospaced fonts lack so many non-ASCII characters that all the glyph substitution makes it really ugly here.

These are (not) a few of my favourite fonts: Medley by WordPress

Edit: Looking around two days later, you can see complaints (I guess… I haven’t read them) here, here, here, etc., and the userscript here.

Written by S

Sun, 2011-06-05 at 04:35:52

Posted in compknow

Making audio louder with Audacity

leave a comment »

(Tried with Audacity 1.3.12 beta.)

  1. Open the file in Audacity. Go to Effects → Amplify.
  2. The amplification set is already the maximum possible without clipping. Don’t change anything, just click OK

This makes the file as loud as possible without clipping: without the loudest parts of the “signal” getting lost. If the result is not loud enough, the problem is not with the loudest parts (they are already as loud as they can be), but with the softer parts. So you need a transformation that makes the soft parts louder while keeping the loud parts the same. This is Dynamic range compression: the dynamic range (difference between softest and loudest parts) is compressed.

So, after trying “Amplify”,

  1. Download “Chris’s dynamic compressor” from here (direct link).
  2. Save the file compress.ny in /Applications/Audacity/plug-ins
  3. In Audacity, go to “Effects → Compress dynamics…” (or perhaps it’s called “Compress &dynamics…”)
  4. The first control (“Compress ratio”) is the main one. Or just leave it as it is. Click OK.
  5. If still not loud enough, go back and increase Compress ratio. Of course, increasing it means decreasing the dynamic range — increase it too much and the parts meant to be soft will be no softer than the rest.

Written by S

Sat, 2011-05-21 at 04:57:44

Posted in compknow

Converting old PS files (generated with LaTeX) to searchable PDFs

with 8 comments

pkfix fasc3a.ps fasc3a-fix.ps
ps2pdf fasc3a-fix.ps

A common (or at least, more common than it should be) scenario: you find a PostScript file of some paper, clearly written in (La)TeX, but which looks blurry on screen and you cannot copy any text. Converting to PDF with, say, ps2pdf does not help either. You curse the .ps format, and put up with the blurriness or print it out (where it looks fine) to read it.

Turns out it doesn’t have to be this way. The problem is that the PS file is using bitmap fonts, but assuming you have the scalable (Type 1) versions of those same fonts on your system, you can convert the fonts! There’s a script called pkfix, distributed with TeX Live, which will take a ps file that uses bitmap fonts and try to convert it to use scalable fonts. Just run it as

pkfix inputfile.ps outputfile.ps

This should produce a PS which isn’t blurry and is searchable, but if you prefer PDF, the usual way will work

ps2pdf outputfile.ps

or on Mac OS X if you don’t have ps2pdf for some reason, o inputfile.ps -a macps2pdf where macps2pdf comes with MacGhostView.

If the file is very old (generated with dvips from before 1996) and pkfix doesn’t work, there’s a further script called pkfix-helper that may make the file appropriate for pkfix.

BTW, if it’s your own files that are coming out blurry, something is wrong with your setup. Just install the package cm-super from CTAN—sudo tlmgr install cm-super or whatever—and no other change is needed. Or you can use the lmodern fonts with \usepackage{lmodern}, but that shouldn’t be necessary.

Written by S

Thu, 2011-05-05 at 11:42:30

Posted in compknow

Tagged with , ,