Scheme: Save preprocessor output for all compiled files
This is a wrapper for the MSVC compiler (cl.exe) to generate a .i file as well as a .obj. Compiled with Bigloo.
(module cl-wrap (main main)) (define (quote-args args) (let loop ((args args) (result "")) (if (null? args) result (loop (cdr args) (string-append result " \"" (car args) "\""))))) (define (main args) ; Run cl.exe to compile (let ((exit-code (system (string-append "cl" (quote-args (cdr args)))))) (if (not (= 0 exit-code)) (exit exit-code))) ; Run cl.exe to produce preprocessed .i (let ((exit-code (system (string-append "cl /P" (quote-args (cdr args)))))) (if (not (= 0 exit-code)) (exit exit-code))) ; /P puts the file in the current directory, so we need to move it to the ; same directory the object would have been in. Get the target directory from ; the /Fo option and the source name from the .(c|cpp). (let ((cpp-filename #f) (obj-filename #f)) (let loop ((args (cdr args))) (cond ((null? args) #f) ((and (>= (string-length (car args)) 3) (string=? (substring (car args) 0 3) "/Fo")) (set! obj-filename (substring (car args) 3 (string-length (car args)))) (loop (cdr args))) ((or (string=? (suffix (car args)) "cpp") (string=? (suffix (car args)) "c") (string=? (suffix (car args)) "cxx")) (set! cpp-filename (car args)) (loop (cdr args))) (else (loop (cdr args))))) (let ((i-file (string-append (prefix (basename cpp-filename)) ".i"))) (copy-file i-file (string-append (prefix obj-filename) ".i")) (delete-file i-file))))
Python: List files older than or newer than a specific date and time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import os, sys from datetime import date, timedelta, datetime from time import localtime import re files = os.listdir('c:/windows/system32/') files = [ f for f in files if re.search('.dll$', f, re.I)] files.sort() d = datetime.now() - timedelta(days=30) d = d.timetuple() oldfiles = 0 newfiles = 0 for file in files: filetimesecs = os.path.getmtime('c:/windows/system32/' + file) filetime = localtime(filetimesecs) # print "*******************************" # print file # print filetime # print "*******************************" if filetime < d: oldfiles += 1 if filetime > d: newfiles += 1 print "Old Files: %s" % oldfiles print "New Files: %s" % newfiles |
Welcome!
Welcome to Jigcode.com! My name is David Andrzejewski. My colleague Jason Felice and I decided to start this site during a quick afternoon coffee break at work. Well, it wasn’t really at work – we simultaneously decided that we just had to get out of the office.
While on the way back from our coffee excursion, we began talking about throwaway code, and how our temp directories are filled with lots of random files, like foo.c, q.py, blargo.bat, and so-forth that do one shot things like “replace the letter ‘L’ at the end of even numbered lines.” We discussed how we usually clean out our temp directories every once in a while, and always end up deleting code that might end up being useful in the future.
We started talking about committing our throwaway code into SVN, and perhaps organizing it a bit to keep it in our back pocket in case we need it again. Then Jason said it: Let’s start a website to collect it. I thought it was a fantastic idea, and here we are!
We started thinking about names for the website. Jason remembered a quote from The Pragmatic Programmer:
When woodworkers are faced with the task of producing the same thing over and over, they cheat. They build themselves a jig or template. If they get the jig right once, they can reproduce a piece of work time after time. The jig takes away complexity and reduces the chances of making mistakes, leaving the craftsman free to concentrate on quality.
We’re actually co-opting this from The Pragmatic Programmer and repurposing it just a little bit (around the edges) for this site.
They were referring to writing code that writes code, but those dusty brain cells of Jason’s responsible for remembering that context failed him during that discussion.
WordNet offers up this definition:
A device that holds a piece of machine work and guides the tools operating on it
Well, that’s much closer to what we were thinking. Weird searches and replaces, things that update ini files, code frobbing, getting file versions, batch version controlled file renames, dead code finding hacks and the like.
So please, enjoy the site – and feel free to send us your own jig code – we’d love to see it! And who knows. You could help some other programmer out in the process.

