Skip to content

Instantly share code, notes, and snippets.

View amitpatelx's full-sized avatar

Amit Patel amitpatelx

View GitHub Profile
@micalexander
micalexander / last_modified_file.rb
Created July 20, 2015 18:29
Ruby: Get last modified file from a directory
def get_last_modified(dir)
# make sure the files to be checked are in the provided directory
files = Dir.new(dir).select { |file| file!= '.' && file!='..' }
# make sure the file has been written to
return nil if (files.size < 1)
# create an array of all the files
files = files.collect { |file| File.join(dir , file) }
@maxivak
maxivak / Reame.md
Last active October 3, 2021 15:04
using Solr search with Rails app

Using Solr search engine with Sunspot gem in Rails app

Solr search engine

http://lucene.apache.org/solr/

Sunspot

Sunspot - Sunspot is a Ruby library for interaction with the Solr search engine.

@innermond
innermond / pdfimage
Last active October 13, 2022 10:23
Extract images from pdf but, surprise! The images that contain alpha channels are extracted as two images. The source and the mask, as they are stored inside pdf file. This script recombine them into an one png file with given transparency
#/usr/bin/bash
# extract images from pdf at first-hand
#prefix=pict
#echo extract images from "$1"
#pdfimages -j "$1" $prefix
# IMAGES ARE SAVED SECVENTIALLY AS IMAGE AND THE NEXT IS A MASK IMAGE !!!!
declare -a files=($(ls *.ppm *.pbm))
mask=
image=
for (( i = 0; i < ${#files[*]}; i = i + 2 ))
@martindemello
martindemello / chain-of-responsibility.rb
Created February 20, 2015 21:30
chain of responsibility example in ruby
class PurchaseApprover
# Implements the chain of responsibility pattern. Does not know anything
# about the approval process, merely whether the current handler can approve
# the request, or must pass it to a successor.
attr_reader :successor
def initialize successor
@successor = successor
end
@jasper502
jasper502 / README
Last active December 30, 2022 18:07
Devise with additional user fields, nested models / attributes and custom routes
The idea here is that I have a single User login that can eventually be tied to multiple Companies via the Role.
You signup via Devise on the custom /register route and fillout the Company information etc. The custom registration controller creates the Role during the user creation and sets a few other attributes.
It all worked but now it's broken and I have no idea what I did to break it.
When I try to create a new user / company the additional user fields (name_first & name_last) always fail validation regardless if they are in fact valid. The nested Company fields do not validate at all. If I enter the email and password field only the form works but only creates the User record.
To me it seems like the custom registration controller is not being processed at all.
@keewon
keewon / test.rb
Created February 4, 2015 08:42
Convert Markdown slim to HTML
# Do 'gem install redcarpet'
# Usage:
# ruby test.rb > test.html
#
require 'slim'
s = File::open('markdown.html.slim').read()
@gbuesing
gbuesing / ml-ruby.md
Last active December 3, 2024 08:13
Resources for Machine Learning in Ruby

UPDATE a fork of this gist has been used as a starting point for a community-maintained "awesome" list: machine-learning-with-ruby Please look here for the most up-to-date info!

Resources for Machine Learning in Ruby

Gems

@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / baruco.org -notes
Created October 29, 2014 06:17
Fast Ruby - Barcelona ruby conference video notes
=================================
def slow(&block)
block.call
end
def slow
Proc.new.call
end
- The below one is 5 times faster then above, in execution
@mahemoff
mahemoff / uniq.rb
Created September 12, 2014 00:29
Ensure Sidekiq jobs are unique (if the queue contains several jobs with same class and args, this will delete all but one of them)
def self.uniq! queue_name
seen_already = Set.new
Sidekiq::Queue.new(queue_name).each { |job|
key = { job.klass => job.args }
key.in?(seen_already) ? job.delete : seen_already << key
}
end
@xpepper
xpepper / Massive file upload using JQueryUpload + Nginx + Rails + Sidekiq.md
Last active December 13, 2023 01:00
Massive file upload using JQueryUpload + Nginx + Rails + Sidekiq

Massive file upload using JQueryUpload + Nginx + Rails + Sidekiq

The goal: Upload several files (virtually big files) to a Rails application without compromising the user experience.

Architecture

jQuery File Upload + Nginx + Rails (Carrierwave) + Sidekiq

  1. jQuery File Upload (http://blueimp.github.io/jQuery-File-Upload/)