Skip to content

Instantly share code, notes, and snippets.

@madhums
madhums / environment.rb
Created March 28, 2011 08:17
Upload images to paperclip with remote uri's
require 'open-uri'
@madhums
madhums / browseimage.html.erb
Created March 28, 2011 08:26
Using flickr image search api in rubyonrails
<form id="imagesearch" action="/modelname/imagesearch" method="post" >
Search for an image
<input type="text" name="query" class="floatleft" />
<input type="submit" name="submit" value="submit"/>
</form>
<center>
<div id="imageresults"></div>
</center>
@madhums
madhums / searchd
Created April 1, 2011 15:35
running searchd manually
searchd --pidfile --config config/development.sphinx.conf
@madhums
madhums / mongod
Created July 19, 2011 12:02
mongod init script. Placed in /etc/init.d/mongod
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Mongodb startup script
# Description: Mongodb start stop daemon sends SIGINT to terminate
# say man signal to see details
# Please check the startup params and replication options
@madhums
madhums / app.js
Created August 3, 2011 20:20
Express settings for node.js
var express = require('express');
var app = express.createServer();
require('./settings').boot(app);
app.dynamicHelpers({
base: function(){
// return the app's mount-point
// so that urls can adjust. For example
// if you run this example /post/add works
@madhums
madhums / mapreduce.js
Created August 3, 2011 20:33
mapreduce using mongodb and mongoose
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db_name');
// map function
var map = function(){
emit(this.field_to_group_by, {
other_fields: this.other_fields
// list other fields like above to select them
})
}
@madhums
madhums / Capfile
Created August 3, 2011 21:06
node.js multistage deployment using capistrano.
# /Capfile
# you need to install capistrano gem
# gem install capistrano
# gem install capistrano-ext
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'config/deploy'
@madhums
madhums / EOFERROR
Created August 6, 2011 13:22
multipart form data EOFERROR rails
Started POST "/" for 59.97.201.56 at 2011-08-06 06:21:02 -0700
2011-08-06T13:21:02+00:00 app[web.1]:
2011-08-06T13:21:02+00:00 app[web.1]: EOFError (bad content body):
2011-08-06T13:21:02+00:00 app[web.1]:
2011-08-06T13:21:02+00:00 app[web.1]:
2011-08-06T13:21:02+00:00 app[web.1]:
2011-08-06T13:21:02+00:00 app[web.1]: Rendered .bundle/gems/ruby/1.9.1/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (22.9ms)
2011-08-06T13:21:02+00:00 app[web.1]: Error during failsafe response: ActionView::Template::Error
2011-08-06T13:21:02+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:495:in `parse_multipart'
2011-08-06T13:21:02+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:270:in `parse_multipart'
@madhums
madhums / post_data.rb
Created August 8, 2011 12:35
rest client to post data
# git clone https://github.com/kcrawford/rest-client.git
require "rubygems"
require './rest-client/lib/rest_client'
RestClient.post 'http://localhost:9292/', :foo => File.new("public/images/rails.png"), :multipart => true
# RestClient.post 'http://aesthete-api-rack.heroku.com/', :foo => File.new("public/images/rails.png"), :multipart => true
# RestClient.post 'http://posttestserver.com/post.php', :foo => File.new("public/images/rails.png"), :multipart => true
# RestClient.post 'http://aesthete-api.heroku.com/', :foo => File.new("public/images/rails.png"), :multipart => true
@madhums
madhums / imagemagick.err
Created August 11, 2011 02:18
imagemagick jpeg lib missing
if you get this error
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError /tmp/stream20110811-30041-x7rvaq-0.jpg is not recognized by the 'identify' command.
try
$identify whatever_file_name.jpg
if you get something like this
identify: no decode delegate for this image format `madhusudhanms.jpg' @ error/constitute.c/ReadImage/532.