Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile
source "http://rubygems.org"
gem "sinatra"
<h1>{{ site.title }}</h1>
<nav>
<ul>
{% for link in site.menu %}
<li>{{ link }}</li>
{% endfor %}
</ul>
</nav>
@kylefox
kylefox / application.html.haml
Created December 23, 2011 19:25
Basic example of Sprockets manifest.
/ Template markup:
/ Points to the "application.js.coffee" Sprockets manifest.
= javascript_include_tag "application"
@kylefox
kylefox / gist:1482281
Created December 15, 2011 18:44
Passenger uses wrong URL to download PCRE.
PCRE (required by Nginx) not installed, downloading it...
# wget -O /tmp/ubuntu-passenger-7717/pcre.tar.gz ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz
--2011-12-15 18:38:20-- ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz
=> `/tmp/ubuntu-passenger-7717/pcre.tar.gz'
Resolving ftp.csx.cam.ac.uk... 131.111.8.80
Connecting to ftp.csx.cam.ac.uk|131.111.8.80|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/software/programming/pcre ... done.
==> SIZE pcre-8.12.tar.gz ... done.
require 'dalli'
module Carbonmade
module Cache
class MembaseBackend
DEFAULT_SETTINGS = {
:host => '127.0.0.1:11211',
:expires_in => (60 * 60 * 2) # 2 hours
}
@kylefox
kylefox / cache_test.rb
Created December 12, 2011 16:25
How to gracefully handle a Dalli::RingError with a persistent cache connection?
# Things work great at this point.
cache = Dalli::Client.new('127.0.0.1:11211')
cache.get('test') # => nil (it's working!)
# Now shutdown membase completely...
cache.get('test') # => Dalli::RingError
# Now what? Ideally `cache.get` (and other cache functions) would
# fail silently until a connection can be re-established.
def user_status(self, user):
# If the user has no blog (for some reason) they are inactive.
if user.owned_blogs.count() == 0:
return 'Inactive'
# If they only have one blog, their status is that blog's status.
if user.owned_blogs.count() == 1:
blog = user.owned_blogs.all()[1]
status = blog.status
if status == Blog.UNCONFIRMED:
@kylefox
kylefox / join.py
Created December 10, 2011 22:08
it's shit like this, python...
# Python is too stupid to know that you want list items coerced to strings when joining them.
# Instead you must manually cast items to strings -- in this case, integers.
# Strings join fine!
>>> ",".join(['a','b'])
'a,b'
# But not integers!
>>> ",".join([1,2])
Traceback (most recent call last):
@kylefox
kylefox / gist:1452463
Created December 9, 2011 17:23
Show which gems in a Gemfile have newer versions available.
# Install the pre-release of Bundler:
gem install bundler --pre
# Run from within your project directory
bundle outdated
class SpecialThing(Thing):
def save(self, *args, **kwargs):
# If only I could `my_kwarg = kwargs.delete('my_kwarg')
my_kwarg = 'my_kwarg' in kwargs
if my_kwarg:
kwargs.pop('my_kwarg')
result = super(SpecialThing, self).save(*args, **kwargs)
if my_kwarg:
self.do_more_stuff()