Skip to content

Instantly share code, notes, and snippets.

View dineshprabu-freshdesk's full-sized avatar

Dineshprabu S dineshprabu-freshdesk

View GitHub Profile
@dineshprabu-freshdesk
dineshprabu-freshdesk / perform_action_when_element_available.js
Created July 28, 2016 06:29
[JQUERY] Perform an action only when element is Available
jQuery('element').livequery(function(){
//element available now.
});
@dineshprabu-freshdesk
dineshprabu-freshdesk / cookie_read_write.js
Created August 30, 2016 07:32
[javascript] Cookie Read and Write
@dineshprabu-freshdesk
dineshprabu-freshdesk / migration_database_client.rb
Last active August 30, 2016 10:25
[RUBY] Migration Database Client
require 'mysql'
class MigrationDB
def initialize domain, user_name, password, db_name
begin
@db_connection = Mysql.new(domain, user_name, password)
@db_name = db_name
rescue Exception => e
p "Error connecting to DB Server.."
@dineshprabu-freshdesk
dineshprabu-freshdesk / freshdesk_solutions_xml_parser.rb
Last active September 6, 2016 06:29
Freshdesk Solutions XML Parsing
require 'ruby-cheerio'
require 'mysql'
class MigrationDB
def initialize domain, user_name, password, db_name
begin
@db_connection = Mysql.new(domain, user_name, password)
@db_name = db_name
rescue Exception => e
@dineshprabu-freshdesk
dineshprabu-freshdesk / custom_field_updation_with_api_v2.js
Created September 1, 2016 05:46
Custom Field Updation with API v2
<script>
var api_key = "API-KEY";
function update_custom_field(ticket_field_id, callback){
var payload = '{"custom_fields":{"account": "{{ticket.company.account}}"}}';
var url = 'https://'+window.location.hostname+window.location.pathname.replace('/helpdesk','/api/v2')
jQuery.ajax({
type: 'PUT',
url: url,
data : payload,
@dineshprabu-freshdesk
dineshprabu-freshdesk / hash_to_csv_conversion.rb
Created September 6, 2016 07:24
Hash to csv conversion
require 'csv'
#writes hash to csv file
def write_to_csv title, hashv
CSV.open("#{title}.csv", "w", :write_headers=> true, :headers => hashv.first.keys) do |csv|
hashv.each do |h|
csv << h.values
end
end
end
require 'active_support/all'
def json_to_xml root_key, file_name
file_name = "#{file_name}.json" unless file_name.ends_with? ".json"
xml_doc = '<?xml version="1.0" encoding="UTF-8"?>'+"<#{root_key}s>"
(File.readlines file_name).each do |line|
hash_to_xml = (JSON.parse(line).to_xml)
xml_doc = xml_doc + (((hash_to_xml.gsub "<hash>", "<#{root_key}>").gsub "</hash>", "</#{root_key}>").gsub('<?xml version="1.0" encoding="UTF-8"?>', ''))
end
xml_doc = xml_doc+"</#{root_key}s>"
@dineshprabu-freshdesk
dineshprabu-freshdesk / freshdesk_xml_parser.rb
Last active October 13, 2016 13:37
Freshdesk XML Parser
require 'ruby-cheerio'
require 'mysql'
class MigrationDB
def initialize domain, user_name, password, db_name
begin
@db_connection = Mysql.new(domain, user_name, password)
@db_name = db_name
rescue Exception => e
@dineshprabu-freshdesk
dineshprabu-freshdesk / zendesk_xml_splitter.rb
Last active October 12, 2016 13:50
Zendesk XML Splitter
require 'nokogiri' # gem install nokogiri
require 'ruby-cheerio' # gem install ruby-cheerio
#Specify the file name to be chunked here
xml_file = "tickets.xml";
#No of chunks to be made
no_of_chunks = 4
doc = Nokogiri::XML(File.open(xml_file));
@dineshprabu-freshdesk
dineshprabu-freshdesk / loading_multiple_csv_files_into_mysql.rb
Created October 7, 2016 02:35
Loading Multiple CSV Files into MySql
require 'mysql' # gem install mysql
require 'csv'
db_name = "" # Database Name
db_connection = Mysql.new("localhost","root","","#{db_name}") # Change the creds, if needed.
csv_files = Dir["*.csv"] # Script goes to the current directory of the csv files.
csv_files.each do |csv_file|
headers = (CSV.read csv_file)[0]
db_connection.query "CREATE TABLE IF NOT EXISTS #{csv_file.split('.')[0]}("+headers.map{|c| "`#{c}` TEXT"}.join(',')+")"
p "table created for #{csv_file} "