September 18th, 2009 § § permalink
Working on a very basic twitter background generator, right now focusing on how to get the sidebar width right. It is very much under use at my twitter handle @dipankarsarkar (http://twitter.com/dipankarsarkar). The core idea is to be abe to communicate more information about what i do as a person using the background image. Some features that I personally want are
- Transparency for the sidebar – The image underneath should be visible, right now its a grey opaque color.
- A right sidebar – After some research , I figured out that the safest and optimal width to cater for is 1200px, with the core content on the left sidebar though. More thoughts on that as I deploy some new changes.
- Better fonts – Although new fonts / languages can be deployed. The code is not flexible enough right now to add new fonts.
That is a long enough list for the day
, attaching the background with this as well. Let me know in case having cool backgrounds excite you.
November 18th, 2008 § § permalink
This is a basic tutorial on how to get CodeIgniter facebook application on nginx (with the gotchas). The nginx configuration would be like the following
server {
listen 80;
server_name blah.com;
location ~ /index.php/ {
root /home/production/blah;
index index.html index.htm index.php;
include conf/fcgi.conf;
fastcgi_param SCRIPT_FILENAME /home/production/fb_apps/quickdate/index.php;
fastcgi_pass 127.0.0.1:9000;
}
access_log /usr/local/nginx/logs/blah.access_log;
error_log /usr/local/nginx/logs/blah.error_log;
}
The critical line is the fastcgi_params parameter, that changes the whole game. In the code Igniter application you need to add the following file in [app]/system/application/libraries/FB_controller.php
facebook = new Facebook($this->API_KEY, $secret);
$this->uid = $this->facebook->require_login();
}
}
?>
There are some significant changes in the configuration which is at [app]/system/application/config/config.php
$config['enable_query_strings'] = TRUE;
$config['subclass_prefix'] = 'FB_';
$config['uri_protocol'] = "REQUEST_URI";
Now in the application you should write controllers extending the above defined class , for example I modified the welcome controller.
facebook->api_client->Users_isAppUser()) {
$this->facebook->redirect($this->facebook->get_add_url());
return;
}
}
catch (Exception $x) {
// Clear cookies for your application and redirect them to a login prompt
$this->facebook->expire_session();
$facebook->redirect($this->facebook->get_login_url());
}
}
function index() {
}
}
Fire this up and see it all running smoothly, this is basically compiled from all kinds of forum over the internet. Thought it will be useful for someone. In case of any issues contact me at me@dipankar.name.
November 18th, 2008 § § permalink
When you are using a platform like django you realise how slow sessions can get when you are using the database as a backend. The problem of using a memory cache like memcached is the fact that when you restart the server to refresh the cache or remove stale objects, the problem is that you lose your sessions data and a lot of people using your site get logged out. The only solution to this problem is to use 2 memcached instances , one for your regular python objects and another for your sessions objects … this is not a default feature in Django. So here is the solution to this particular problem.
In your project directory create the following files, the first file is basically a copy of a core django file (contrib/sessions/backends/cache.py) and the second is a file where the class gets initialized (its not necessary , but a good example).
/session_backend.py
from django.contrib.sessions.backends.base import SessionBase, CreateError
from kwippyproject.session_cache import cache
class SessionStore(SessionBase):
"""
A cache-based session store.
"""
def __init__(self, session_key=None):
self._cache = cache
super(SessionStore, self).__init__(session_key)
def load(self):
session_data = self._cache.get(self.session_key)
if session_data is not None:
return session_data
self.create()
return {}
def create(self):
# Because a cache can fail silently (e.g. memcache), we don't know if
# we are failing to create a new session because of a key collision or
# because the cache is missing. So we try for a (large) number of times
# and then raise an exception. That's the risk you shoulder if using
# cache backing.
for i in xrange(10000):
self.session_key = self._get_new_session_key()
try:
self.save(must_create=True)
except CreateError:
continue
self.modified = True
return
raise RuntimeError("Unable to create a new session key.")
def save(self, must_create=False):
if must_create:
func = self._cache.add
else:
func = self._cache.set
result = func(self.session_key, self._get_session(no_load=must_create),
self.get_expiry_age())
if must_create and not result:
raise CreateError
def exists(self, session_key):
if self._cache.get(session_key):
return True
return False
def delete(self, session_key=None):
if session_key is None:
if self._session_key is None:
return
session_key = self._session_key
self._cache.delete(session_key)
/session_cache.py
from django.core.cache.backends.memcached import CacheClass
from django.conf import settings
scheme, rest = settings.SESSION_CACHE.split(':', 1)
host = rest[2:-1]
cache = CacheClass(host,{})
In your settings file you need to make the following changes
/settings.py
SESSION_ENGINE = "kwippyproject.session_backend"
SESSION_CACHE = 'memcached://127.0.0.1:11200/'
Restart, start a memcached server on port 11200 and see your site becoming that much more faster
. Keep coding and in any problems with this approach feel free to mail me on me@dipankar.name.