Skip to content

Instantly share code, notes, and snippets.

View paveltyk's full-sized avatar

Pavel Tsiukhtsiayeu paveltyk

  • BILL
  • North Carolina, US
  • 19:43 (UTC -05:00)
View GitHub Profile
@paveltyk
paveltyk / gist:668919
Created November 9, 2010 09:57
Mail Chimp Test Task
# Mail Chimp Test Task
API_KEY = 'api-key'
LIST_NAME = 'list name'
require 'rubygems'
require 'xmlrpc/client'
require 'active_record'
# === Database Setup
output_file = File.open 'gem_remote_output.txt', 'w'
File.open 'gem_remote_input.txt' do |input_file|
input_file.each_line do |line|
match = line.match /^([^_\-][\-\w\.]*) \(([\d\.]*).*\)$/
output_file.puts "gem install #{match[1]} -v #{match[2]}" if match
end
end
output_file = File.open 'activemerchant_gateway_output.rb', 'w'
output_file.puts "PAYMENT_GATEWAYS = {"
File.open 'activemerchant_gateway_input.txt' do |input_file|
input_file.each_line do |line|
match = line.match /^.*?(\w*).rb:.*class (\w*)Gateway.*$/
next unless match
output_file.puts " \"#{match[1]}\" => {"
output_file.puts " :name => \"#{match[2]}\","
output_file.puts " :class => ActiveMerchant::Billing::#{match[2]}Gateway"
output_file.puts " },"
letters = 'satire'
dictionary = {}
results = []
File.open("/usr/share/dict/words", "r") do |infile|
while line = infile.gets
word = line.chomp.downcase
next if word.size != 7
key = word.chars.sort.join
@paveltyk
paveltyk / jquery.twit_char_counter.js
Created March 10, 2011 11:27
TwitCharCounter jQuery plugin
/*!
* jQuery TwitCharCounter Plugin
* version: 1.0 (10-MAR-2011)
* created by: PavelTyk
*
* This is a simple char counter plugin (like the Twitter one). It has flexible
* settings and allows minimize configuration settings.
*
* Examples and documentation at: https://gist.github.com/863967
@paveltyk
paveltyk / tabs.js
Created April 20, 2011 13:13
jQuery simple tabs
$('ul.tab-controls li').bind('click', function() {
$(this).addClass('active').siblings().removeClass('active')
.parents('#funbox').find('ul.tab').hide().eq($(this).index()).fadeIn(500);
return false;
});
// HTML:
// <div id="funbox">
// <ul class="tab-controls">
// <li class="active"><a href="#">Featured</a></li>
@paveltyk
paveltyk / gist:1002213
Created June 1, 2011 12:41
My solution to highlight correct menu item (using simple_navigation gem), when :create action fails
# In config/simple_navigation.rb
require 'simple_navigation/rails_controller_methods'
ActionController::Base.class_eval do
def self.disable_navigation_auto_highlighting(*args)
around_filter :temporary_disable_simple_navigation_auto_highlighting, *args
end
def temporary_disable_simple_navigation_auto_highlighting
auto_highlight = SimpleNavigation::Configuration.instance.auto_highlight
@paveltyk
paveltyk / attachment_fu.rake
Created June 23, 2011 22:56
Ever needed to refresh (regenerate, update) attachment_fu attachments on amazon-s3? Here you go!
def logger
@logger_for_attachment_fu_rake_task ||= Logger.new STDOUT
end
def raise_with_logger(msg)
logger.error msg
raise msg
end
def obtain_class
@paveltyk
paveltyk / hide_confirmation.jquey.js
Created July 27, 2011 19:16
jQuery plugin to auto show/hide confirmation field
/*!
* jQuery HideConfirmation Plugin
* version: 1.0 (27-JUL-2011)
* created by: PavelTyk https://github.com/PavelTyk
*
* This is a simple plugin to automatically hide confirmation fields if
* no changes made to observed field.
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
@paveltyk
paveltyk / mock_geocoder.rb
Created October 10, 2011 14:48
Geocoder: Stub out address geocoding during RSpec unit tests
# In spec_helper:
# RSpec.configure do |config|
# ...
# config.include(MockGeocoder)
# end
#
# In your tests:
# it 'mock geocoding' do
# mock_geocoding! # You may pass additional params to override defaults (i.e. :coordinates => [10, 20])
# address = Factory(:address)