Skip to content

Instantly share code, notes, and snippets.

Thanashyam Raj thanashyam

Block or report user

Report or block thanashyam

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View names_and_emails_from_multiple_addresses.rb
def names_and_emails_from_multiple_addresses(addresses)
if addresses.is_a? String
addresses = addresses.split(/,|;/)
end
addresses = addresses.collect do |address|
next if address.blank?
address = address.gsub('"','').gsub("'",'')
matches = address.strip.scan(/(\w[^<\>]*)<(\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,10}\b)\>\z|\A<!--?((\b[A-Z0-9._%+-]+)@[A-Z0-9.-]+\.[A-Z]{2,10}\b)-->?\z/i)
@thanashyam
thanashyam / time_conversion.rb
Created Jan 19, 2013
*Time Conversion Helper Methods*: Converting seconds into HH::MM format Converting Time in HH:MM format or in decimal format into seconds
View time_conversion.rb
#Converting seconds into HH::MM format
def get_time_in_hours seconds
Time.at(seconds).utc.strftime("%H:%M")
end
#Converting Time in HH:MM format or in decimal format into seconds
def convert_duration(duration)
if duration =~ /^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
time_pieces = duration.split(":")
hours = time_pieces[0].to_i
@thanashyam
thanashyam / jquery.md5.js
Created Apr 5, 2012
Jquery MD5 - downloaded from: http://plugins.jquery.com/project/md5 (which is no longer available)
View jquery.md5.js
/**
* jQuery MD5 hash algorithm function
*
* <code>
* Calculate the md5 hash of a String
* String $.md5 ( String str )
* </code>
*
* Calculates the MD5 hash of str using the » RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash.
* MD5 (Message-Digest algorithm 5) is a widely-used cryptographic hash function with a 128-bit hash value. MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of data. The generated hash is also non-reversable. Data cannot be retrieved from the message digest, the digest uniquely identifies the data.
@thanashyam
thanashyam / sso_login_freshdesk.php
Last active Dec 29, 2019
SSO Login for Freshdesk support portal - PHP Sample Code (Updated)
View sso_login_freshdesk.php
<?php
define('FRESHDESK_SHARED_SECRET','____Place your Single Sign On Shared Secret here_____');
define('FRESHDESK_BASE_URL','http://{{your-account}}.freshdesk.com/'); //With Trailing slashes
function getSSOUrl($strName, $strEmail) {
$timestamp = time();
$to_be_hashed = $strName . FRESHDESK_SHARED_SECRET . $strEmail . $timestamp;
$hash = hash_hmac('md5', $to_be_hashed, FRESHDESK_SHARED_SECRET);
return FRESHDESK_BASE_URL."login/sso/?name=".urlencode($strName)."&email=".urlencode($strEmail)."&timestamp=".$timestamp."&hash=".$hash;
}
@thanashyam
thanashyam / gist:1144920
Created Aug 14, 2011
Updating values of "Age from" and "Age To" select inputs based values from the other
View gist:1144920
$('#agefrom').live('change',function() {
var age_from = parseInt($('#agefrom').val());
var age_to = parseInt($('#ageto').val());
if (age_to < age_from) {
$('#ageto option:selected').removeAttr('selected');
if (age_from < 99) {
$('#ageto option[value="'+ String(age_from + 1) + '"]').attr('selected','selected');
} else {
You can’t perform that action at this time.