November 28th, 2008 Luke
If you’ve ever wanted to slideLeft or slideRight in jQuery, you may have noticed that you…can’t. You can slideUp and slideDown, but not slideLeft or slideRight. Why is this? I don’t know. I do know that getting those effects is a single line, though:
obj.animate({width:'show'});
obj.animate({width:'hide'});
obj.animate({width:'toggle'});
Simple, and easy to use. But why isn’t it in the core?
Posted in javascript | No Comments »
October 17th, 2008 Luke
Need to dump your Django project’s sqlite database to a file? Turns out it’s as easy as a one-liner:
echo '.dump' | ./manage.py dbshell > dump.sql
Posted in Code | No Comments »
September 23rd, 2008 Luke
Recently, I was tasked with building a ‘clear cache’ button for a Django project. While this is something that I’m sure a lot of people have approached, none of them seem to have shared their code. Here’s what I came up with:
1
2
3
4
5
6
7
8
9
10
11
12
| from django.core.cache import cache
try:
cache._cache.clear() # in-memory caching
except AttributeError:
# try filesystem caching next
old = cache._cull_frequency
old_max = cache._max_entries
cache._max_entries = 0
cache._cull_frequency = 1
cache._cull()
cache._cull_frequency = old
cache._max_entries = old_max |
Posted in Code, django, python | No Comments »
June 25th, 2008 Luke
For a recent project, I had to deal with a fair number of controls on a page that all needed to be disabled at once. This is the function that I wrote to do so:
void DisableControls(List types, ControlCollection controls) {
foreach(Control control in controls) {
if(types.Contains(control.GetType())) {
((WebControl)control).Enabled = false;
}
}
}
Posted in ASP.Net, Code, csharp, snippet | No Comments »
June 10th, 2008 Luke
For a recent project, we needed to store as many possible values into 3 characters as we could, based on a numeric ID. So, we created a function that would convert that ID to base 62, which we could then use to increase the number of available combinations that we could store. Here’s the function:
public const string base62digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public string ToBase62(int input)
{
int modulo;
string sTemp = "";
do
{
modulo = input % 62;
sTemp = base62digits.Substring(modulo + 1, 1) + sTemp;
input = input / 62;
} while (input != 0);
return sTemp;
}
It’s been modified from the VB code to do the same thing, which you can find here.
Posted in Code, conversions, csharp | No Comments »