Skip to content

Instantly share code, notes, and snippets.

@NeMO84
NeMO84 / delicious_importer.rb
Last active August 29, 2015 14:07
A script to help you import exported bookmarks from delicious back into delicious. It can probably easily be tweaked to work with Safari, Chrome, Firefox HTML exports.
#!/bin/ruby
require 'www/delicious'
require 'nokogiri'
require 'cgi'
module WWW
class Delicious
class Post < Element
@NeMO84
NeMO84 / tables_collation_changer.sql
Last active August 29, 2015 14:10
Convert collation for multiple tables easily
# Original: http://stackoverflow.com/questions/10859966/how-to-convert-all-tables-in-database-to-one-collation
SELECT CONCAT("ALTER TABLE ", TABLE_NAME," COLLATE <COLLATION_VALUE>") AS ExecuteTheString
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA="<SCHEMA_NAME>"
AND TABLE_TYPE="BASE TABLE";
# Execute selected scripts.
{
"color_scheme": "Packages/Theme - Spacegray/base16-ocean.dark.tmTheme",
"font_options": "subpixel_antialias",
"font_size": 14,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage",
"Markdown"
@NeMO84
NeMO84 / log
Created January 7, 2011 23:27
the issue seems to be if I put :ids => /\d/ or :constraints=>{:ids => /\d/} then I get a RuntimeError (route set not finalized):
Started POST "/login.xml" for 127.0.0.1 at 2011-01-07 15:17:10 -0800
RuntimeError (route set not finalized):
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.7ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.6ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.2ms)
@NeMO84
NeMO84 / Activity 1.6.rb
Created January 11, 2011 09:01
Let me know if things can be improved from both a coding perspective and a performance perspective. Thanks!
# Nirmit Patel
MAX_NUMBER = 100
MIN_NUMBER = 1
MAX_NUMBER_OF_GUESSES = 8
computers_number = rand(MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER
puts "Hello player. What is your name?"
name = gets
name = name.chomp
def numeric?(object)
true if Float(object) rescue false
end
def get_user_response(message, validate_is_number = true)
valid = false
input = nil
loop do
puts message
input = gets.chomp
if validate_is_number
array1 = [1, 2, 3, 4]
array2 = %w{peter piper picked peppers}
array3 = []
# You need to write some code in this part
# to make the program output "Success"
array3 = array1.collect{|i| i.to_s}.zip(array2).flatten
if array3 == ['1', 'peter', '2', 'piper', '3', 'picked', '4', 'peppers']
puts "Success"
CONFIRMATIONS = ["y","yes","sure","yup","why not"]
def get_list_of_names
puts "Please enter a list of words (one,two,three...):"
input = gets.chomp.downcase
input.split(",")
end
def sanitize(names_array)
names_array = names_array.uniq
end
@NeMO84
NeMO84 / sqlserver_adapter.rb
Created February 4, 2011 02:39
lib/active_record/connection_adapters/sqlserver_adapter.rb
def primary_key(table_name)
identity_column(table_name).try(:name) || columns(table_name).first.try(:name)
end
ActiveResource::Formats::XmlFormat.decode("<a><b></b></a>")
=> {"b"=>nil}
# Is there any way to to change the xml, such that, we could yeild the following: {"b"=>""}