Skip to content

Instantly share code, notes, and snippets.

require "rubygems"
require 'RMagick'
include Magick
## Image that you want to resize
img = ImageList.new(File.join(Rails.root,'public',self.logo_image.to_s))
## Resize Parameter
img.resize!(self.logo_width.to_i, self.logo_height.to_i)
## Resize to filed name you want to use
img.write(File.join(Rails.root,'public',self.logo_image.to_s))
@meetme2meat
meetme2meat / ruby_spider.rb
Last active October 14, 2015 02:17
Gist To download File from File Directory exposed via Web Server
require "rubygems"
require "net/http"
require "open-uri"
require "fileutils"
## BASE_DIR where the file will be stored
BASE_DIR = ""
def open_url(url)
begin
url = File.join(BASE_PATH,url)
> - In ruby 1.8.x, what is the functional difference between rb_thread_schedule and rb_thread_select?
rb_thread_schedule() is the guts of the thread scheduler, it traverses
over the linked list of threads (several times) to find the next one
to switch into. The function is long (250 lines) and messy, and covers
all the combinations of thread status (RUNNABLE, TO_KILL, STOPPED,
KILLED) and wait state (FD, SELECT, TIME, JOIN, PID).
If there are no threads doing i/o or waiting on a timeout,
rb_thread_schedule() picks another thread from the list (considering
@meetme2meat
meetme2meat / api_strategies.rb
Created January 8, 2014 13:27
WARDEN SETUP
Rails.configuration.middleware.use RailsWarden::Manager do |manager|
manager.default_strategies :api_authentication
## Write a failure app
manager.failure_app = CustomFailureApp #Proc.new { |env| ['200',{'Content-Type' => 'text/html'},['Logout You Idiot']] }
end
Warden::Strategies.add(:api_authentication) do
def valid?
params[:user] and (params[:user][:email] || params[:user][:password])
@meetme2meat
meetme2meat / gist:8521107
Created January 20, 2014 14:48
Fix for multiple delete
$('body').on('click','.deleteFacadeButton',function() {
var checkedVal = $('#deleteAssocShareatives').is(':checked');
deleteFacade(facadeIdToDelete, checkedVal);
$('#show-all-facades').trigger('click');
hideModal($('#deleteFacadeModal'));
})
// Deleting a Facade FIXME - remove the inner event outside
$('body').on('click', '.facadeDelete', function(event){
tell application "SystemUIServer"
set actionSelected to the button returned of (display dialog "What you want to do?" buttons {"Send file", "Receive file"} default button 2)
if actionSelected = "Send file" then
set filepath to POSIX path of (choose file)
display dialog "Please enter IP address of receiver:" default answer ""
set ipAddress to text returned of result
if ipAddress = "" then
repeat
display dialog "IP address cant be blank,Please enter IP address of receiver:" default answer ""
require 'rubygems'
require 'json-schema'
## /poaster_instance.json
## Seem like the need to have access_control a part of this json
poaster_instance_schema = {
"type" => "object",
"required" => ['id','facades','name'],
"properties" => {
"id" => {"type" => "string"},
"name" => {"type" => "string"},
...
...
...
use Warden::Manager
use Rack::Mongoid::Middleware::IdentityMap
use ExceptionNotifier
use OmniAuthMiddleware ## <--
use OmniAuth::Builder
run MyAppliction::Application.routes
@meetme2meat
meetme2meat / client1.rb
Last active January 28, 2016 12:24
Celluloid Client-1.
require 'celluloid/zmq'
Celluloid::ZMQ.init
class Client
include Celluloid::ZMQ
def initialize
@socket = Socket::Push.new
begin
@meetme2meat
meetme2meat / client2.rb
Last active January 28, 2016 12:24
This is 2nd Client for Celluloid example
require 'celluloid/zmq'
Celluloid::ZMQ.init
class Client
include Celluloid::ZMQ
def initialize
@socket = Socket::Push.new
begin