Skip to content

Instantly share code, notes, and snippets.

@rsalvado
rsalvado / poor's man pagination.rb
Created July 25, 2008 12:45
Poor's man pagination trick
# 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]
require 'spec_helper.rb'
describe "Migration" do
before(:all) do
MyModel = Object.new
require 'my_migration'
end
before(:each) do
@avinashv
avinashv / anagram.py
Last active March 18, 2021 21:09
A command-line anagram solver using the Linux/OS X wordlist.
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
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"
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
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?"
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
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; } }
};
#@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>
#!/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