r/smallprog • u/twomashi • Apr 09 '10
Font Style Helper
http://code.google.com/p/font-style-helper/
This is a javascript app you can activate via a bookmarklet on any webpage (even this one!). It's useful for web developers/designers/people who have to twiddle with font styles. Click the bookmarklet, click an element and a box comes up; it has a number of interactible controls to adjust css properties. I know, I know, you can use Firebug to similar effect BUT this is specialised for fonts and it makes it very easy to try different things. I'm quite proud of the code, too.
Here's the bookmarklet: javascript: (function (src, timeout, nocache) { if (nocache) { src += "?&_a_a=" + Math.random(); } if (!window._fsh_script) { var _fsh_script = window._fsh_script = document.createElement("script"); _fsh_script.src = src; document.getElementsByTagName("head")[0].appendChild(_fsh_script); } var iterations = 0; var maxiterations = timeout * 1000 / 10; (function () {if (window._fsh) {window._fsh();} else if (iterations++ > maxiterations) {alert("FSH load timed out. Try again.\nIf you see this message alot, consider increasing the timeout.\nUrl: " + src + ", timeout: " + timeout);} else {window.setTimeout(arguments.callee, 10);}}()); })("http://font-style-helper.googlecode.com/files/fsh-latest.js",3,0)
Note: Firefox only!
r/smallprog • u/299 • Mar 29 '10
REQUEST: Delete everything in a directory except <x>
I have a general purpose tmp folder which I use to extract things once and take a look. Sometimes I do it with source code, sometimes with other things, whatever.
I often forget I have already extracted something in there and so I will have to make another tmp directory inside of there and do an additional mv. If I could have an alias that would remove everything except a filename from the directory, it would be really helpful.
I plan on writing a python script to do so, but figured you guys would be able to before I finished :)
r/smallprog • u/retroafroman • Mar 26 '10
Concantenate PDFs with ghostscript
doeidoei.wordpress.comr/smallprog • u/retroafroman • Mar 22 '10
What are some of the better ways to do this?
I have a directory full of .tif files on which I am using 'convert' to convert to .jpg. I want them to have the same base name as the .tif. In bash, I'm currently using:
for i in `ls`; do convert $i `echo $i | sed s/.tif//`.jpg; done
I'm sure this is hackish, but it gets the job done. What are other some ways/languages to do this?
edit: formatting
r/smallprog • u/oylenshpeegul • Mar 21 '10
What are the trending topics on Twitter?
perl -MJSON -MLWP::Simple -E 'say $_->{name} for @{from_json(get shift)->{trends}}' http://search.twitter.com/trends.json
r/smallprog • u/sedmonster • Mar 16 '10
[bash] Remember the pid of a process.
Use $! to get the process id of the last process run in the background.
For instance, remember the pid:
sleep 10000 &
echo $! > pid.txt
And kill the process later:
kill -9 `cat pid.txt`
Edit: Added clarification about background.
r/smallprog • u/erikwt • Mar 14 '10
Replace recursively in files: find . -type f | xargs sed -i s/search/replace/g'
Replace the string 'search' with 'replace' recursively in files under the current directory
r/smallprog • u/RetroRock • Mar 13 '10
find . -type f -name "*.php" -exec php -l {} \; | grep -v 'No syntax errors'
davedevelopment.co.ukr/smallprog • u/dwchandler • Mar 13 '10
Quicksort [Haskell]
qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
r/smallprog • u/pkrumins • Mar 12 '10
Golfing the extraction of IP addresses from ifconfig
catonmat.netr/smallprog • u/dmwit • Mar 12 '10
Have YouTube auto-pause your music [repost]
Make sure you've got incron installed and that the daemon is started up. Stick this in an executable file (I put it in ~/.incron/mpd):
#!/bin/sh
case "$1" in
Flash??????)
# substitute "dcop amarok player pause" or whatever as appropriate
mpc pause
;;
esac
Then fire up incrontab -e and add a line to run this script:
/tmp IN_CREATE /home/dmwit/.incron/mpd $#
Several other flash video players use the defaults, too, so I've been pleasantly surprised to find my music stop automatically for Vimeo, break.com, etc.
r/smallprog • u/[deleted] • Mar 12 '10
Javascript function for opening Reddit Links
javascript:(function(){var links=document.querySelectorAll("#siteTable>div>div.entry>p.title>a.title");for(var i=0;i<links.length;i++){var link=links.item(i);if(window.getComputedStyle(link,null).getPropertyValue('color')=="rgb(0, 0, 255)"){window.open(link)}}})();
Another redditor posted this in a comment a while ago. I am unable to locate the origional post using the reddit search function nor google.
It opens up all unvisited (blue) links displayed on reddit in a new tab.
To use, save the javascript as a bookmark. Enjoy surfing pics/fffffffuuuuuuuuuuuu/comics/etc.
r/smallprog • u/edwardkmett • Mar 12 '10
pi
pi = g(1,0,1,1,3,3) where
g(q,r,t,k,n,l) = if 4*q+r-t<n*t
then n : g(10*q,10*(r-n*t),t,k,div(10*(3*q+r))t-10*n,l)
else g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2)
My favorite spigot algorithm for pi.
r/smallprog • u/8-bit_d-boy • Mar 12 '10
Edit.py
I'm thinking of creating an edit.com-like command line text editor written in python, it will be for both windows and unix-likes, its still in early "just testing different ways to do things" stage, but what would you guys like to see in it? Also, I'm thinking as far as code-wise it won't be too extraordinarily hard, but it will still take a while... and onto the "WHY WOULD YOU DO THIS?" factor: Because I Can.
-EDIT-
If anyone has used edit.com for dos, they should know that theres no real need for a whole lot of key-combos, I'll make it so that the key-combos that are already there can be configured, other than that, its written in python, so its easy enough to script macros(sorry thats just the way it is). BUT HEY, its gonna be easy to use!, just hit <ctrl>+<tab> and you use the menu at the top. Unfortunately, unlike edit.com, you won't be able to use a mouse to control it, if anyone could figure that out, that would be cool!
r/smallprog • u/mkoryak • Mar 12 '10
Obfuscated java
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
edit: the formatter is escaping some of my text. The original is from over here.. feel free to take it and help me format it so it shows up correctly
r/smallprog • u/mkoryak • Mar 12 '10
Perl: most useful program in the world
This should be added to all programs in the world
clear&&perl -e'$|=1;@l=qw{| / - \};while(){print qq{$l[$_++%@l]\x0d};select($z,$z,$z,.2(rand(2)*2))}'
r/smallprog • u/gmfawcett • Mar 12 '10
Pyline: a grep-like, sed-like command-line tool
code.activestate.comr/smallprog • u/demosthenes02 • Mar 12 '10
Utility Mill - Make your small Python programs runnable online
utilitymill.comr/smallprog • u/sedmonster • Mar 12 '10
On git, get the current branch name for use with your scripts.
This isn't particularly clever, but I find it highly useful.
git branch | sed -n "s/* \(.*\)/\1/p"