Skip to content

Instantly share code, notes, and snippets.

View michelson's full-sized avatar
🏠
Working from home

Miguel Michelson Martinez michelson

🏠
Working from home
View GitHub Profile
module Paperclip
class Attachment
class UploadedPath
attr_reader :original_filename, :content_type, :size, :path
def initialize(uploaded_file)
@original_filename = uploaded_file["name"].downcase
@content_type = uploaded_file["content_type"].to_s.strip
@file_size = uploaded_file["size"].to_i
@path = uploaded_file["path"]
def move_to_s3
temp_path = attachment.path
temp_file = attachment.to_file # Paperclips way of getting a File object for the attachment
# Save it as a regular attachment
# this will save to S3
s3_upload = Upload.find(id) # Same db record but we need the S3 version
s3_upload.attachment = temp_file # reset the file - it will assume its a new file
s3_upload.save! # Paperclip will upload the file on save
curl = Curl::Easy.new('http://metrik.tricdev.com:3000/tablero')
curl.perform
curl.cookies = session_id
curl.perform
puts curl.perform.body_str
# ----------------------------------------------
# Class for Youtube (youtube.com)
# http://www.youtube.com/watch?v=25AsfkriHQc
# ----------------------------------------------
class VgVimeo
def initialize(url=nil, options={})
# general settings
// togglea values de inputs
InputValueHelper = $.klass({
initialize: function(){
this.initial_value = $(this.element).val()
},
onblur: function(){
if($(this.element).val() == '') {
$(this.element).val(this.initial_value);
}
require 'net/pop'
module Mailman
class Receiver
# Receives messages using POP3, and passes them to a {MessageProcessor}.
class POP3
# @return [Net::POP3] the POP3 connection
attr_reader :connection
@michelson
michelson / gist:805882
Created February 1, 2011 13:55
examples for lazy high chart
##### controllers
@time_chart = HighChart.new('chart_tag') do |f|
f.chart({:zoomType =>'x', :defaultSeriesType => 'spline'})
f.title(:text => 'Flower Market')
f.x_axis({:type =>'datetime'})
f.y_axis({:title => 'flowers'})
chart_begin_js = "Date.UTC(#{@last_x_days[0].year}, #{@last_x_days[0].month-1}, #{@last_x_days[0].day})"
f.series(:name => 'violets', :data => generate_numbers(number), :pointInterval => 24*3600*1000)
f.series(:name => 'sunflowers', :data => generate_numbers(number), :pointInterval => 24*3600*1000)
end
@michelson
michelson / gist:986130
Created May 23, 2011 02:38 — forked from gma/gist:674141
Bluepill config for resque
ENV["PATH"] = "/opt/ruby/bin:#{ENV['PATH']}"
ENV["RAILS_ENV"] = "production"
ENV["QUEUE"] = "*"
Bluepill.application("nichelator") do |app|
app.working_dir = "/var/apps/nichelator/current"
app.uid = "app"
app.gid = "app"
2.times do |i|
app.process("resque-#{i}") do |process|
Uploadizr = $.klass({
initialize: function(submiter , path ){
//console.log("picker!! " +submiter+" "+$(this.element).attr("token")+" "+path);
var current_id = "";
var token = $(this.element).attr("token")
var uploader = new plupload.Uploader({
runtimes : "html5",
browse_button : $(this.element).attr("id"),
max_file_size : '10mb',
url : path,
@michelson
michelson / gist:1368246
Created November 15, 2011 20:33
fast deploy in rails 3.1
# comment out "deploy/assets" in your capfile, we are doing this locally
namespace :noumad do
desc "Compress assets in a local file"
task :compress_assets do
run_locally("rm -rf public/assets/*")
run_locally("bundle exec rake assets:precompile")
run_locally("touch assets.tgz && rm assets.tgz")