July 27th, 2009
by Chris
.........................................................
¶
In my desire to finally completely work through K&R I decided to start at the beginning. The fruit of today’s labor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| #include <stdio.h>
main(){
int fahr, celcius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
while (fahr <= upper){
celcius = (fahr - 32) / 1.8;
printf("%d\t%d\n", fahr, celcius);
fahr = fahr + step;
}
} |
A very simple bit of C without a lot of depth of fancy hackery that converts the temps in Fahrenheit starting at 0 to 300 degrees in intervals of 20 to Celsius.
Continue Reading
July 6th, 2009
by Chris
.........................................................
¶
Recently I have been doing a bit of work using JS to build the entire DOM for a page after only passing it a JS Array of the contents, this technique works quite well to reduce server load as all the processing is done on the client’s site with identical templating information sent to everyone, and only an array that is different.
One problem while writing code this way is that I needed a simple way to insert an entire template into one line of JS code. Most everything was html, which meant new line and tab characters were pretty prevalent. All I needed was a simple script to strip out new lines and tabs, sounds like a perfect job for Python.
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
33
| #!/usr/bin/env python
# encoding: utf-8
"""
htmlMinimizer.py
Created by Christopher King on 2009-07-03.
Copyright (c) 2009 Strogn Consulting. All rights reserved.
"""
#imports
import os, string
#files and containers
sourceFile = open('inputFile.html', 'rw')
destFile = open('outputFileOneLine.html', 'wb')
destContainer = ""
#itterative work
for line in sourceFile:
lineContent = str(line)
lineContent = lineContent.strip("\t")
lineContent = lineContent.rstrip("\n")
destContainer = destContainer + lineContent
#file writing
destFile.write(str(destContainer))
#file closing
sourceFile.close()
destFile.close()
#confirmation message
print "Document Minimized!" |
Continue Reading
June 20th, 2009
by Chris
.........................................................
¶
Ah, a fresh install of WordPress…. New design is out mostly and the time has come to apply some content. Normally I delete this post and start my ow but considering this is a programming / web design blog it seemed an appropriate enough title. So without further ado, the first bit of code:
Simple Python snippet to parse a TSV(tab separated value) into a list:
1
2
| for line in open('fileName.tsv', 'rU'):
lineEntry = line.split('\t') |
jQuery powered script to hide a given div on pageload
1
2
3
4
| $(document).ready( function(){
$(this).find(".divToHide").hide();
return false;
}); |
That’s all for now, check back again soon.
Continue Reading