Skip to content

Instantly share code, notes, and snippets.

import System.Random
randPairs :: (RandomGen g, Random a) => (a,a) -> g -> [(a,a)]
randPairs range gen = zip as bs
where (a,b) = split gen -- create two separate generators
as = randomRs range a -- one infinite list of randoms
bs = randomRs range b -- another
seed = 13561956 :: Int
mygen = mkStdGen seed
@robhurring
robhurring / Rakefile
Created December 7, 2010 20:09
Delayed Job with Sinatra -- without sinatra specific gems, etc.
task :environment do
require './dj-sinatra'
end
namespace :jobs do
desc "Clear the delayed_job queue."
task :clear => :environment do
Delayed::Job.delete_all
end
@koshigoe
koshigoe / mount-ram.sh
Created February 11, 2011 14:57
Like tmpfs in Mac OSX
#!/bin/sh
# This program has two feature.
#
# 1. Create a disk image on RAM.
# 2. Mount that disk image.
#
# Usage:
# $0 <dir> <size>
#
@chrisbloom7
chrisbloom7 / README.md
Created June 6, 2011 07:16
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@roman
roman / gsub.hs
Created June 14, 2011 01:36
Nahive implementation of a gsub
module Text.Regex.Gsub
(gsub) where
import Text.Regex.Posix ((=~), MatchText)
import Data.Array ((!))
import Data.Char (isDigit)
-------------------------------------------------------------------------------
gsub :: String -> String -> String -> String
gsub text match replacement = replaceMatches 0 matches text
@kares
kares / scheduled_job.rb
Created June 14, 2011 11:31
Recurring Job using Delayed::Job
#
# Recurring Job using Delayed::Job
#
# Setup Your job the "plain-old" DJ (perform) way, include this module
# and Your handler will re-schedule itself every time it succeeds.
#
# Sample :
#
# class MyJob
# include Delayed::ScheduledJob
@rdj
rdj / active_admin.rb
Created July 1, 2011 06:39
active_admin custom filter
# config/initializers/active_admin.rb
require 'active_admin_custom_filter'
ActiveAdmin.setup do |config|
# ...
end
@keiya
keiya / gist:1190856
Created September 3, 2011 08:22
convert polar - cartesian
// thx tomy! http://www5.airnet.ne.jp/tomy/cpro/sslib12.htm
function cartesian2polar(x,y,z) {
var obj = new Object;
obj.r = Math.sqrt( x*x + y*y + z*z );
if (x != 0.0)
obj.phi = Math.atan2( y, x );
else {
if (y < 0.0)
@carlohamalainen
carlohamalainen / shrink_pdf.sh
Created November 8, 2011 00:46
Shrink a PDF file by transferring to DJVU, then PS, then back to PDF.
#!/bin/bash
set -o nounset # explode on undefined variables
set -e # explode if any command fails
# Best way to shrink a PDF of scanned pages without losing quality. Found on
# http://ubuntuforums.org/archive/index.php/t-1133357.html
# example: ./shrink_pdf.sh big_file.pdf 600 small_file.pdf
@kanru
kanru / pdf-ocr.sh
Created January 19, 2012 08:19
PDF OCR
#! /bin/sh
# Batch OCR pdf files to text files
#
# Copyright (C) 2012 Kan-Ru Chen <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#