Skip to content

Instantly share code, notes, and snippets.

View sleekslush's full-sized avatar

Craig Slusher sleekslush

  • Philadelphia, PA
View GitHub Profile
@sleekslush
sleekslush / apply-pattern.js
Created July 26, 2011 19:58
Javascript apply pattern
var Public = Public || {};
Public.Namespace = Public.Namespace || {};
(function() {
function concat(s1, s2) {
return s1 + s2;
}
this.sayHello = function(who) {
console.log(concat("Hello ", who));
@sleekslush
sleekslush / gist:1260184
Created October 3, 2011 20:43
Client-side smash markup
<html>
<head>
<link rel="stylesheet/wesumo" type="text/css" href="http://meyerweb.com/eric/tools/css/reset/reset.css" />
<link rel="stylesheet/wesumo" type="text/css" href="http://a.fsdn.com/sd/classic.css?release_20110818.02" />
<script type="text/javascript" src="wesumo.debug.js?key=po0eYa_0R9W1QZ8Q7BGRiw&smash=css"></script>
</head>
<body>
<span id="message">Smash that shit</span>
<script type="text/wesumo-js" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<script type="text/wesumo-js" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
@sleekslush
sleekslush / gist:1260266
Created October 3, 2011 21:11 — forked from madzak/gist:1260246
Client-side smash markup
<html>
<head>
<link rel="wesumosheet" type="text/css" href="http://meyerweb.com/eric/tools/css/reset/reset.css" />
<link rel="wesumosheet" type="text/css" href="http://a.fsdn.com/sd/classic.css?release_20110818.02" />
<script type="text/javascript" src="wesumo.debug.js?key=po0eYa_0R9W1QZ8Q7BGRiw&smash=css"></script>
</head>
<body>
<span id="message">Smash that shit</span>
<script type="wesumoscript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script>
<script type="wesumoscript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.js"></script>
@sleekslush
sleekslush / formset_updateview_example.py
Created January 6, 2012 06:42
An example of extending UpdateView to use a formset instead of a form
class UserUpdateView(AuthenticatorViewMixin, UpdateView):
model = User
template_name = 'manager/authenticator/user_list.html'
def get_form_class(self):
return modelformset_factory(User, extra=0)
def get_form_kwargs(self):
kwargs = super(UserUpdateView, self).get_form_kwargs()
kwargs['queryset'] = kwargs['instance']
@sleekslush
sleekslush / gist:1650519
Created January 21, 2012 00:57
Queryset example with DetailView
class MyView(DetailView):
def get_queryset(self):
queryset = super(MyView, self).get_queryset()
return queryset.filter(my_cool_field=42)
@sleekslush
sleekslush / gist:1650547
Created January 21, 2012 01:01
Slug field name example with DetailView
# urls.py
urlpatterns = patterns('',
url(r'^something/(?P<slug>\d+)/$', MyView.as_view()),
)
# views.py
class MyView(DetailView):
slug_field = 'my_cool_field'
@sleekslush
sleekslush / gist:1667396
Created January 24, 2012 02:23
Adding request user to a form save
class MyView(CreateView):
model = Team
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.user = self.request.user
self.object.save()
return FormMixin.form_valid(self, form)
@sleekslush
sleekslush / gist:1676619
Created January 25, 2012 14:53 — forked from dnoyes/gist:1674741
creating a team (django)
# teams/views.py
@login_required()
def create(request):
form = CreateTeamForm(request.POST or None, request.FILES or None)
if form.is_valid():
team = form.save(commit=False)
team.status = STATUS.ACTIVE
team.creator = request.user
team.save()
When I'm configuring in a Django app, what is the purpose of the djcelery models? Right now tables get created, but nothing flows into them. Is this the database backend replacement for Redis and RabbitMQ? Or is it something else?
Why do workers delete items from the queue if they are unable to process them (i.e. task wasn't found)?
What is the best way to identify if a task, based on id, exists in the queue and what its status is?
How do I know if a task id is even valid?
What is the preferred way to run 2 celeryd processes that are intended to handle different tasks? (i.e. proc 1 doesn't handle tasks that proc 2 is responsible for and vice versa)
@sleekslush
sleekslush / gist:2713507
Created May 16, 2012 20:01
HTTP protocol logic in javascript
// Stupid as shit
var url = (("https:"==document.location.protocol)?"https":"http") + "://domain.com/file.js";
// Better
var url = document.location.protocol + "//domain.com/file.js";
// Best (protocol-less FTW!)
var url = "//domain.com/file.js";