Posted by
seon on Friday, July 11
Recently I modified my home template to render only the latest X articles.
I changed this:
1
|
{% include 'article' with articles %}
|
... into this:
1
2
|
{{ site | latest_articles: 5 | assign_to: 'recent_articles' }}
{% include 'article' with recent_articles %}
|
I am not really satisfied with this markup. Is there a more concise solution that does not involve local variable assignment?
Posted by
seon on Monday, September 03
A few code snippets using CodeRay filters for syntax highlighting.
lang=”ruby”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
require 'coderay'
class CodeMacro < FilteredColumn::Macros::Base
def self.filter(attributes, inner_text = '', text = '')
lang = attributes.delete(:lang)
attributes[:line_numbers] = :table unless attributes.has_key?(:line_numbers)
attributes.each do |key, value|
attributes[key] = value == 'nil' ? nil : value.to_sym rescue nil
end
begin
CodeRay.scan(inner_text, lang.to_sym).html(attributes)
rescue ArgumentError
CodeRay.scan(inner_text, lang.to_sym).html(:line_numbers => :table)
rescue
unless lang.blank?
RAILS_DEFAULT_LOGGER.warn "CodeRay Error: #{$!.message}"
RAILS_DEFAULT_LOGGER.debug $!.backtrace.join("\n")
end
"<pre><code>#{inner_text}</code></pre>"
end
end
end
|
lang=”javascript”
1
2
3
4
5
6
7
|
fixIEOverlapping: function() {
Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
this.iefix.style.zIndex = 1;
this.update.style.zIndex = 2;
Element.show(this.iefix);
},
|
Posted by
seon on Tuesday, August 28
I’ve hopped on board the Nginx + Mongrel train for my website (mephisto, rails, mysql, mongrel cluster, nginx – deployed with vlad capistrano v2). After some brief wrangling with apache conf files, I took a break and looked over Nginx. Turns out it’s pretty simple to get up and running. The best thing about nginx aside from its small memory foot print (compared to Apache2) is the ability to hot-swap new binaries using unix kill signals. The nginx configuration can also be reloaded on-the-fly. Nginx is a sweet little daemon.
Here are some of the steps I followed to get it up and running on Debian Etch. These instructions assume you know/have already installed the appropriate ruby gems.
Compiling nginx/0.5.31 (updated 09/05/2007)
1
2
3
4
5
6
7
8
9
|
apt-get install libpcre3
apt-get install libpcre3-dev
wget http://sysoev.ru/nginx/nginx-0.5.31.tar.gz
tar xzvf nginx-0.5.31.tar.gz
cd nginx-0.5.31
./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-cc-opt="-I /usr/include/pcre"
make
sudo make install
|
Configuration summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
+ threads are not used
+ using system PCRE library
+ using system OpenSSL library
+ md5 library is not used
+ sha1 library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/sbin"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "/usr/local/nginx/client_body_temp"
nginx http proxy temporary files: "/usr/local/nginx/proxy_temp"
nginx http fastcgi temporary files: "/usr/local/nginx/fastcgi_temp"</code>
|
Nginx configuration (updated 09/05/2007)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
worker_processes 2;
error_log current_path/log/nginx.error.log debug;
pid shared_path/pids/nginx.pid;
events {
worker_connections 1024;
}
http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log current_path/log/nginx.access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 70;
gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_comp_level 9;
gzip_proxied any;
gzip_types application/xml application/javascript application/x-javascript application/atom+xml application/rss+xml;
gzip_types text/css text/html text/javascript text/js text/plain text/xml;
upstream mongrel {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
server {
listen 80;
server_name fucema.net www.fucema.net;
root current_path/public;
index index.html index.htm;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host "www.fucema.net";
proxy_redirect false;
proxy_max_temp_file_size 0;
# rewrite 'fucema.net' -> 'www.fucema.net'
if ($host = 'fucema.net' ) {
rewrite ^/(.*)$ http://www.fucema.net/$1 permanent;
}
# if static file exists serve now, skip rewrite rules
if (-f $request_filename) {
expires max;
break;
}
# redirect feed requests to feedburner, unless its the feedburner agent
if ($http_user_agent !~ FeedBurner) {
rewrite ^/feed/atom.xml$ http://feeds.feedburner.com/fucema;
}
if (-f $request_filename/index.html) {
expires 7d;
rewrite (.*) $1/index.html break;
}
# support rails page caching
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
# pass it onto upstream mongrel cluster
if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov).*?$ {
root current_path/public;
if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root current_path/public;
}
}
}
|
Mongrel cluster configuration
1
2
3
4
5
6
7
8
9
|
---
cwd: current_path
log_file: log/mongrel.log
environment: production
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
port: "8000"
servers: 2
|