Kiasyn's Blog

27Oct/111

IE9 couldn’t be downloaded

If you are getting this error in IE9, there is a simple fix, but no always easy to find ;)

Untick this bad boy:

Filed under: Uncategorized 1 Comment
29Apr/110

Script summary: Failed loading then steps

This Kaseya error can be quite annoying to diagnose if you don't know what to look for.

It is caused by having a step (such as Set Registry Value) with < or > in it, as Kaseya use XML to save their scripts.

You can double tag it, eg <<br>> instead of <br> and it will run as expected.

Filed under: Uncategorized No Comments
21Apr/110

Searching Recent Event Logs with C#

Hi guys,

Today I was looking into event log searching. I run a script that does a chkdsk on reboot but then when the machine boots I want to see the log from that report.

To do this, I search the registry for the most recent event within a certain time period (I choose 1 day). We can use Linq to make the filtering quite easy.

EventLog el = new EventLog();
el.Log = log;
el.MachineName = ".";

try
{
var result = (from EventLogEntry elog in el.Entries
where (elog.TimeGenerated >= DateTime.Now - new TimeSpan(days, 0, 0, 0))
&& (elog.Source.ToString().Equals(source))
&& (elog.EventID == id)
orderby elog.TimeGenerated descending
select elog).First();
Console.WriteLine(result.Message);
}
catch (InvalidOperationException)
{
Console.WriteLine("No results found. ");
}

Cheers to StackOverflow for the basis of this code.

Filed under: Uncategorized No Comments
14Aug/100

RVM, Merb, Rake and RSpec

I was having terrible difficulty getting Merb to work with RSpec. Turns out that Merb now uses Bundler, and if you don't edit your Gemfile to include rspec it bails on you.

  sam@shiny-dev:~/Projects/mojo$ rake db:migrate
    (in /home/sam/Projects/mojo)
    Merb root at: /home/sam/Projects/mojo
    /home/sam/.rvm/gems/ruby-1.9.1-p378@merb/gems/dm-validations-1.0.0/lib/dm-validations.rb:33: warning: already initialized constant OrderedHash
    Loading init file from ./config/init.rb
    Loading ./config/environments/development.rb
    rake aborted!
    no such file to load -- spec/rake/spectask
    /home/sam/Projects/mojo/Rakefile:24:in `require'
    (See full trace by running task with --trace)

This was solved by adding the line:

gem "rspec", :require => "spec"

to the bottom of the Gemfile in the project root.

Filed under: Uncategorized No Comments
28Mar/100

Ruby chat-server with Fibers & Eventmachine

Posting this mostly for my reference so I don't lose it again later.

require 'rubygems'
require 'eventmachine'

class Connection < EventMachine::Connection
  attr_accessor :fiber, :name
  def initialize
    @fiber = Fiber.new { poll }
    @name = nil
  end

  def post_init
    (@@connections ||= []) << self
    @fiber.resume
  end
  def poll
    send_data( "What is your name?" )
    @name = Fiber.yield
    send_data( "OK, your name is #{@name}\n")

    loop do
      msg = Fiber.yield
      @@connections.each do |conn|
        conn.send_data( "#{@name} said: #{msg}\n")
      end
    end
  end
  def receive_data( data )
    @fiber.resume data.strip
  end
end

EventMachine.run do
  EM.start_server "0.0.0.0", 2000, Connection

end
Filed under: Uncategorized No Comments
29Jan/100

FUSS++

A while ago I started work on an improved version of SMAUG FUSS

While I since got distracted and stopped work on it, I'm releasing what I did so the community can continue it.

I place no additional license on the work I have added.

Note: It currently does not compile, but if you do get it to compile it you can use lua within mobprogs, roomprogs etc. I think I setup most of the triggers, eg rand triggers, drop, etc.

A lot of the commands I didn't set up, mpgoto etc, but they could be done better now with the lua support anyway.

It is available for download, here

Filed under: Uncategorized No Comments
19Dec/090

Converting from VMWare to Virtualbox

Yesterday I used Virtualbox for the first time, to create a Beowulf cluster.

Today, I am migrating my Ubuntu VM from VMWare Player to VirtualBox.

This is dead simple with a linux client:

  1. Copy your VMware image to your Virtualbox VM location
  2. Open up VirtualBox and go File->Virtual Media Manager
  3. Add the .vmdk file as a hard disk in the Virtual Media Manager
  4. Create a new VM, using the hard disk you copied as the disk.

That's it! Could it be simplier? :)

For Windows, things are a bit more difficult. See this link for more details.

Filed under: Uncategorized No Comments
29Nov/090

String matching with C++ PCRE

bool regex_match( const char *pattern, const std::string str, std::vector *substrings )
{
	const char *err;
	int erroffset = 0;
	pcre *re = pcre_compile( pattern, 0, &err, &erroffset, NULL );
	int ovector[90];
	size_t rc;
	if ( !re )
	{
		bug( "%s: regular expression compilation failed at: %d: %s", __FUNCTION__, erroffset, err );
		return false;
	}
	if ( ( rc = pcre_exec(re, NULL, str.c_str(), str.length(), 0, 0, ovector, 90 ) ) < 0 )
		switch( rc )
		{
			case PCRE_ERROR_NOMATCH:	return false;
			default:	bug( "%s: Matching error: %d", __FUNCTION__, rc );	return false;
		}
	if ( substrings )
		for ( size_t i = 0; i < rc; i++ )
			substrings->push_back( str.substr( ovector[2*i], ovector[2*i+1] - ovector[2*i] ) );
	return true;
}
bool simple_match( const char *pattern, const char *str )
{
	std::string newPattern = "^";

	for ( size_t i = 0; i < strlen(pattern); i++ )
	{
		if ( !isalnum( pattern[i] ) && !iscntrl(pattern[i]) )
		{
			if ( pattern[i] == '*' )
			{
				newPattern += ".*";
				continue;
			}
			else
				newPattern += '\\';
		}
		newPattern += pattern[i];
	}
	newPattern += "$";
	return regex_match( newPattern.c_str(), str, NULL );
}
Filed under: Uncategorized No Comments
25Nov/092

no such file to load — mkmf (LoadError)

Ever get this error when installing a gem?

/usr/bin/ruby1.9 extconf.rb install mysql
extconf.rb:10:in `require': no such file to load -- mkmf (LoadError)
        from extconf.rb:10:in `
'

It happens when you don't have the development library installed. Easy enough to fix, just install ruby1.9-dev.

For ubuntu:

sudo apt-get install libruby1.9
Filed under: Uncategorized 2 Comments
25Nov/090

Ruby utility script to send email

Someone over at MUDBytes asked about sending emails from within their game. They were looking to do this from C++, which as we all know is a pain in the ass.

I wrote up this quick utility script in ruby for sending emails easily, without the risk of passing stuff to the command line.

Usage:

ruby sendemail.rb
from@nospam.com
to@nospam.com
My Subject
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean ornare, magna eu feugiat rhoncus, tellus tellus pulvinar lacus,
sit amet malesuada risus leo id eros.

Pellentesque placerat arcu nec massa hendrerit tristique.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

CTRL-C

This is an easy way of sending emails, and can be configured to authenticate with a server.

# Copyright (c) 2009 Sam O'Connor
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'rubygems'
require 'net/smtp'
require 'tmail'
require 'optparse'
require 'ostruct'

options = OpenStruct.new
options.smtp_server = 'localhost'
options.smtp_port = 25
options.smtp_user = nil
options.smtp_pass = nil
options.smtp_authtype = nil

opts = OptionParser.new do |opts|
  opts.banner = "Usage sendmail.rb [options]\n\n\n\n"
  opts.separator ""
  opts.separator "Specific options:"

  opts.on("-s", "--server [SERVER]", "Use a different SMTP server", "") do |server|
    options.smtp_server = server
  end
  opts.on("-p", "--port [PORT]", Integer, "Use a different SMTP port.", "") do |port|
    options.smtp_port = port
  end
  opts.on("-u", "--user [USER]", String, "Authenticate with a user", "") do |user|
    options.smtp_user = user
  end
  opts.on("-p", "--pass [PASS]", String, "Password for user", "") do |pass|
    options.smtp_pass = pass
  end
  opts.on("-t", "--type [TYPE]", [:plain, :login, :cram_md5], "Select authentication type (plain ,login, cram_md5). Normally use plain") do |t|
    options.smtp_authtype = t
  end
  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end
end

mail = TMail::Mail.new
mail.from = $stdin.gets
mail.to = $stdin.gets
mail.subject = $stdin.gets
body = String.new
until $stdin.eof?
  body << $stdin.gets
end
mail.body = body

smtp = Net::SMTP.new(options.smtp_server, options.smtp_port )
smtp.start( 'localhost.localdomain', options.smtp_user, options.smtp_pass, options.smtp_authtype ) do |smtp|
  smtp.send_message( mail.to_s, mail.from, mail.to )
end
Filed under: Uncategorized No Comments