Skip to content

Instantly share code, notes, and snippets.

thanashyam / launch_party_check.rb
Created Jun 12, 2020
Method to check the status of the LaunchParty feature
View launch_party_check.rb
def launched_for?(account)
@store.smembers(account_wise_key(account)).map(&:to_sym) | @store.smembers(everyone_key).map(&:to_sym)
thanashyam / launch_party_toggle.rb
Created Jun 12, 2020
LaunchParty implementation details
View launch_party_toggle.rb
def toggle_for_account(feature, account, launch = true)
method = launch ? :sadd : :srem
@store.send(method, account_wise_key(account), feature)
@store.send(method, feature_wise_key(feature), account)
thanashyam / launch_party_usage_2.rb
Last active Jun 12, 2020
Most important controls using LaunchParty
View launch_party_usage_2.rb
# Opening the gates to everyone, or the general availability
LaunchParty.launch(feature: :custom_translations)
# Stop panicking and quickly roll back the feature from everyone
LaunchParty.rollback(feature: :custom_translations)
thanashyam / launch_party_usage.rb
Last active Jun 12, 2020
Sample usage for LaunchParty
View launch_party_usage.rb
# Launching a feature to an account
# Checking if the feature has been launched
# Reverting the feature from an account
# Listing all the features turned on for the account
View names_and_emails_from_multiple_addresses.rb
def names_and_emails_from_multiple_addresses(addresses)
if addresses.is_a? String
addresses = addresses.split(/,|;/)
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 / 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"%H:%M")
#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 / jquery.md5.js
Created Apr 5, 2012
Jquery MD5 - downloaded from: (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 / sso_login_freshdesk.php
Last active Feb 14, 2020
SSO Login for Freshdesk support portal - PHP Sample Code (Updated)
View sso_login_freshdesk.php
define('FRESHDESK_SHARED_SECRET','____Place your Single Sign On Shared Secret here_____');
define('FRESHDESK_BASE_URL','http://{{your-account}}'); //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 / 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 {