Skip to content

Instantly share code, notes, and snippets.

@thanashyam
thanashyam / launch_party_check.rb
Created June 12, 2020 17:00
Method to check the status of the LaunchParty feature
def launched_for?(account)
@store.smembers(account_wise_key(account)).map(&:to_sym) | @store.smembers(everyone_key).map(&:to_sym)
end
@thanashyam
thanashyam / launch_party_toggle.rb
Created June 12, 2020 17:00
LaunchParty implementation details
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)
end
@thanashyam
thanashyam / launch_party_usage_2.rb
Last active June 12, 2020 17:02
Most important controls using LaunchParty
# 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
thanashyam / launch_party_usage.rb
Last active June 12, 2020 17:02
Sample usage for LaunchParty
# Launching a feature to an account
account.launch(:custom_translations)
# Checking if the feature has been launched
account.launched?(:custom_translations)
# Reverting the feature from an account
account.rollback(:custom_translations)
# Listing all the features turned on for the account
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 January 19, 2013 08:20
*Time Conversion Helper Methods*: Converting seconds into HH::MM format Converting Time in HH:MM format or in decimal format into seconds
#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 April 5, 2012 10:00
Jquery MD5 - downloaded from: http://plugins.jquery.com/project/md5 (which is no longer available)
/**
* 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 November 22, 2022 23:26
SSO Login for Freshdesk support portal - PHP Sample Code (Updated)
<?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 August 14, 2011 14:30
Updating values of "Age from" and "Age To" select inputs based values from the other
$('#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 {