Discover gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Poor's man pagination | |
# http://weblog.jamisbuck.org/2007/2/28/poor-man-s-pagination | |
rows = Person.find(:all, :conditions => { ...}, | |
:limit => page_size+1, :offset => last_offset + page_size) | |
more_results, rows = rows.length > page_size, rows[0,page_size] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper.rb' | |
describe "Migration" do | |
before(:all) do | |
MyModel = Object.new | |
require 'my_migration' | |
end | |
before(:each) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def anagram_solve(letters, words): | |
solution = [word.lower() for word in words if len(word) == len(letters)] | |
for letter in letters: | |
solution = [word for word in solution if letter in word and letters.count(letter) == word.count(letter)] | |
return solution | |
if __name__ == "__main__": | |
import sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buff = "" | |
File.open('1.txt', 'r').each_line do |line| | |
if line =~ /^----- /i && buff != "" | |
puts "--> " + buff | |
puts "[ " + tags.join(", ") + " ]" | |
while rline= gets do | |
tag= rline.chomp! | |
print "--> " + tag | |
break if tags.include?(tag) | |
print " not okay.\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'coffee' | |
require 'water' | |
require 'cup' | |
require 'carsten' | |
cup = Cup.new(:size => 'small') | |
cup.add(Coffee::Espresso.new(:shots => 3)) | |
cup.add(Water::Ice.new(:cubes => 12)) | |
cup.join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'classifier' | |
require 'madeleine' | |
b = SnapshotMadeleine.new("bayes_data1") { | |
Classifier::Bayes.new 'Weather', 'Politics' | |
} | |
b.system.train_politics "I don't understand democrates and their policies" | |
b.system.train_politics "republicans are losers, mc cain cannot win from the democratic party" | |
b.system.train_weather "it's hot today isn't it? what is it, about 100 degrees?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'coffee' | |
require 'water' | |
require 'cup' | |
require 'carsten' | |
cup = Cup.new(:size => 'small') | |
cup.add(Coffee::Espresso.new(:shots => 3)) | |
cup.add(Water::Ice.new(:cubes => 12)) | |
cup.join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i=1; i < data.page_count; i++) { | |
$('#pageNav').append('<a href="#">'+ i + '</a>'); | |
console.info(i); | |
$('#pageNav a:last').bind("click", function(){ alert( i }); | |
if (i == 9) { if (data.page_count > 12) { $('#pageNav').append('...'); i = data.page_count - 3; } } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@me variable is like current_user | |
<% alert_list = Alert.list(@me, 5) %> | |
<!-- Alerts --> | |
<div id="alerts" class="module"> | |
<div class="module_head"> | |
<h3 class="module_name">Alerts and Notifications</h3> | |
<ul class="module_options cx"> | |
<li><%= link_to(_('View All'), :controller => 'alert', :action => 'list') if not alert_list.empty? %></li> | |
<li><%= link_to(_('Preferences'), :controller => 'user', :action => 'settings', :anchor => 'alerts') %></li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import mpd # Import MPD Library | |
import pyosd # Import OSD Library | |
import time # Import Internal Time Module | |
client = mpd.MPDClient() # Init MPD Client | |
client.connect("localhost", 6600) # Connect to local MPD Server | |
cs = client.currentsong() # Get the currentsong dict | |
if 'title' in cs: # Check to see if "title" title exists in the dict |