Skip to content

Instantly share code, notes, and snippets.

@rajib
rajib / gist:9407297
Created March 7, 2014 07:59
Linkify Message
Utility = function () {
return {
linkify: function (text) {
if (text) {
text = text.replace(
/((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url){
var full_url = url;
if (!full_url.match('^https?:\/\/')) {
full_url = 'http://' + full_url;
@rajib
rajib / gist:5317089
Last active December 15, 2015 20:18
SSL/HTTPS request redirect follow
def get_redirected_page(url)
uri = URI.parse(url)
if uri.scheme == "https"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response['location']
else
@rajib
rajib / workers.rake
Created September 1, 2012 04:55 — forked from karmi/workers.rake
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@rajib
rajib / string_similarity check
Created May 14, 2012 18:41
takes two company names (strings) as an input and returns a similarity index on the scale of 0 to 100.
# http://www.catalysoft.com/articles/StrikeAMatch.html
class Similarity
def initialize(str1, str2)
@str1 = str1
@str2 = str2
@set1 = build_character_pair(str1)
@set2 = build_character_pair(str2)
end
@rajib
rajib / snow osx 64 bit rails bundler env activate for mysql2 gem
Created April 5, 2011 12:01
snow osx 64 bit rails bundler env activate for mysql2 gem
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
env ARCHFLAGS="-arch x86_64"
@rajib
rajib / ruby method to extract emails from a string into an array
Created April 4, 2011 05:28
ruby method to extract emails from a string into an array
def extract_emails_to_array(txt)
reg = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i
txt.scan(reg).uniq
end
input = IO.readlines("in.txt")
output = File.new("mails.txt", "w+")
@rajib
rajib / sendmail
Created February 18, 2011 12:28
sendmail
config.action_mailer.delivery_method = :sendmail
@rajib
rajib / mark_required
Created January 3, 2011 11:48
mark_required
<%= mark_required(@user, :email) %>
# module ApplicationHelper
# def mark_required(object, attribute)
# "*" if object.class.validators_on(attribute).map(&:class).include? ActiveModel::Validations::PresenceValidator
# end
# end
1. <%= form_for(@user) do |f| %>
2. <%= render "shared/error_messages", :target => @user %>
Twitter = function () {
// user credentials
var username, password, screen_name;
function make_basic_auth(user, password) {
var tok = user + ':' + password;
var hash = Base64.encode(tok);
return "Basic " + hash;
}
function switch_to_main() {
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.js" charset="utf-8"></script>
<script type="text/javascript" src="custom.js" charset="utf-8"></script>
<script type="text/javascript" src="base64.js" charset="utf-8"></script>
<script type="text/javascript" src="jquery.form.js" charset="utf-8"></script>
</head>
<body style="margin:0">
<div id="main">
<div id="loginForm" class="span-10 mLeft45">