Skip to content

Instantly share code, notes, and snippets.

View batasrki's full-sized avatar

Srdjan Pejic batasrki

  • S-Squared Design & Development
  • Toronto, ON
View GitHub Profile
def create
@album = Album.new(params[:album])
if @album.save
@photo = Photo.new(params[:photo])
@photo.album = @album
@photo.save
end
end
import twitter
import sys
from whoosh.fields import Schema, STORED, ID, KEYWORD, TEXT
import os, os.path
from whoosh import store, index
import shelve
from whoosh.qparser import QueryParser
from spambayes import hammie, Options, mboxutils, storage
from spambayes.Version import get_current_version
import email
; HTTP query string parser, Clojure
(defn parse-query-string
"Parses a querystring into a hash"
[qs]
(into {} (map #(vec (.split % "=")) (.split qs "&"))))
# Given a class with an array of files as paths e.g.
# ['path/to/file.txt', 'other/file','path/file','file']
# Will organize them into a hash like
# {
# 'path' => {
# 'to' => {
# 'file' => {}
# },
# 'file' => {}
# },
module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
module Date #:nodoc:
# Enables the use of time calculations within Time itself
module Calculations
# Returns a new Date/DateTime representing the "start" of this week (i.e, Monday; DateTime objects will have time set to 0:00)
def beginning_of_week
days_to_monday = self.wday!=0 ? self.wday-1 : 6
result = self - days_to_monday
self.acts_like?(:time) ? result.midnight : result
<label>Blah</label>
<asp:Textbox id="something" runat="server"></asp:Textbox>
<div class="clear"></div>
TO
<div>
<label>Blah</label>
<asp:Textbox id="something" runat="server"></asp:Textbox>
</div>
#!/usr/bin/env ruby
require 'mathn'
require 'benchmark'
class FindPrime
attr_accessor :limit
def initialize
@limit = 10001
end
def display
<input type="hidden" id="sortCol" name="sortCol">
<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="//root/request/sortCol">
<xsl:value-of select="//root/request/sortCol" />
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</input>
#!/usr/bin/env ruby
#
# A hook script to verify that only syntactically valid ruby code is commited.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Put this code into a file called "pre-commit" inside your .git/hooks
# directory, and make sure it is executable ("chmod +x .git/hooks/pre-commit")
#
# rvm 'gemdir' function, easily switch between any ruby's gem directory.
function gemdir {
if [ -z "$1" ] ; then
echo "gemdir expects a parameter, which should be a valid rvm ruby selector"
else
rvm use $1
cd `rvm gemdir`
pwd
fi
}