Monday, December 1, 2008

How to lock down a computer

For Windows XP.
  • Create limited user account.
  • From admin open gpedit.msc
  • Go to Administrative Templates > System > Run only allowed Windows Applications
  • Define applications as winword.exe, firefox.exe etc.
  • Don't forget whatever you do to include gpedit.msc and mmc.exe otherwise you won't be able to get back in! 
  • Get rid of run... command.

Monday, November 10, 2008

/!\ FAILSAFE /!\ Status: 500 Internal Server Error wrong number of arguments (1 for 0)

/!\ FAILSAFE /!\ Status: 500 Internal Server Error wrong number of arguments (1 for 0)


Problem:
You probably added a method called Send which is causing this error to be thrown.


Rename your method to something other than 'Send'.

http://flexrails.blogspot.com/2008/04/failsafe-mystereous-error-message.html

Saturday, November 8, 2008

installing ruby 1.8.7 on rimuhosting stack

A new installation will automatically install in /usr/local/   whilst your symbolic links are pointing to the installation in /usr/. The initial installation will therefoer not update your ruby version, unless you specify it everytime.

In order to make ruby 1.8.7 the default the symbolic links for ruby/gem/irb/erb/rake  all need to be updated. Then all gems will need to be reinstalled, and indeed the passenger configuration in apache will need to be updated.

Installing mysql gem on rimuhosting server

You'll get a

checking for mysql_query() in -lmysqlclient... no

error if you don't do as follows:

gem install mysql -- --with-mysql-config=/usr/lib/mysql/mysql_config

Thursday, November 6, 2008

How to setup passenger on standard CENTOS5 Rimuhosting Stack


--
7 Lower shrubbery
Radley College
Abingdon
OX14 2HU

Monday, September 29, 2008

Gems & plugins via proxy

On Mac
Gems:
issue option in gem command: -p my.proxy.com:8080
Plugins: set environment variable separately thus
export http_proxy=my.proxy.com:8080

Wednesday, July 9, 2008

How to get a tab separated .txt file of events into Google Calendar

  1. Open .txt file in Notepad.
  2. Add first line with column headers: Start Date TAB End Date TAB etc.
  3. Find/Replace the weird apostrophes that have turned into 'O's with squiggles
  4. Save
  5. Open Outlook.
  6. Import .txt (DOS) file, preferably into a blank calendar
  7. Export from Outlook to .csv file
  8. Upload .csv file to Google Calendar.
  9. Regret not having read these instructions four hours ago.

Saturday, May 17, 2008

How to Show the date in Eruby


<% @today = Date.today %>
<h3 class="date"><span class="month"><%= @today.strftime("%b")%></span> <span
class="day"><%= @today.strftime("%d")%></span><span class="year">,<%= @today.strftime("%Y")%></span></h3>

Wednesday, May 7, 2008

A few things learnt on apache + mongrel cluster

Remember to put in which ports apache is to listen on 
Listen 80
will only listen on 80!

mongrel_rails must be done via sudo (otherwise can't use www as user and group)

Wednesday, April 30, 2008

Gem via proxy

It is well documented as part of gem help that using the following common options:

-p, –[no-]http-proxy [URL]      Use HTTP proxy for remote operations

will allow gem to use the proxy server for remote operations. While this has worked for me before, but recently for some reason I have been getting errors. So, the other alternative that works for me is to set the environment variable HTTP_PROXY as such:

set HTTP_PROXY=http://[proxy url]:[port]

Actually this option is convenient. I have set the above environment variable permanently for the machines that I use at work which are behind proxy servers.


Thursday, April 3, 2008

Testing Mailer in Console

from http://lists.radiantcms.org/pipermail/radiant/2007-February/003394.html

class MyMailer < ActionMailer::Base
def test_email
@recipients = "b@gmail.com"
@from = "blah"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end

MyMailer::deliver_test_email

Wednesday, April 2, 2008

Quick ruby if syntax

>> @order.id.eql?(1)
=> false

String and Float formats

from ruby-doc core
format(format_string [, arguments...] ) => string

sprintf(format_string [, arguments...] ) => string







Returns the string resulting from applying format_string to any
additional arguments. Within the format
string, any characters other than format

sequences are copied to the result. A format sequence consists of a percent sign,
followed by optional flags, width, and precision indicators, then
terminated with a field type character. The field type controls how the
corresponding sprintf argument
is to be interpreted, while the flags modify that interpretation. The field
type characters are listed in the table at the end of this section. The
flag characters are:


  Flag     | Applies to   | Meaning
---------+--------------+-----------------------------------------
space | bdeEfgGiouxX | Leave a space at the start of
| | positive numbers.
---------+--------------+-----------------------------------------
(digit)$ | all | Specifies the absolute argument number
| | for this field. Absolute and relative
| | argument numbers cannot be mixed in a
| | sprintf string.
---------+--------------+-----------------------------------------
# | beEfgGoxX | Use an alternative format. For the
| | conversions `o', `x', `X', and `b',
| | prefix the result with ``0'', ``0x'', ``0X'',
| | and ``0b'', respectively. For `e',
| | `E', `f', `g', and 'G', force a decimal
| | point to be added, even if no digits follow.
| | For `g' and 'G', do not remove trailing zeros.
---------+--------------+-----------------------------------------
+ | bdeEfgGiouxX | Add a leading plus sign to positive numbers.
---------+--------------+-----------------------------------------
- | all | Left-justify the result of this conversion.
---------+--------------+-----------------------------------------
0 (zero) | bdeEfgGiouxX | Pad with zeros, not spaces.
---------+--------------+-----------------------------------------
* | all | Use the next argument as the field width.
| | If negative, left-justify the result. If the
| | asterisk is followed by a number and a dollar
| | sign, use the indicated argument as the width.


The field width is an optional integer, followed optionally by a period and
a precision. The width specifies the minimum number of characters that will
be written to the result for this field. For numeric fields, the precision
controls the number of decimal places displayed. For string fields, the
precision determines the maximum number of characters to be copied from the
string. (Thus, the format sequence
%10.10s will always contribute exactly ten characters to the
result.)



The field types are:


    Field |  Conversion
------+--------------------------------------------------------------
b | Convert argument as a binary number.
c | Argument is the numeric code for a single character.
d | Convert argument as a decimal number.
E | Equivalent to `e', but uses an uppercase E to indicate
| the exponent.
e | Convert floating point argument into exponential notation
| with one digit before the decimal point. The precision
| determines the number of fractional digits (defaulting to six).
f | Convert floating point argument as [-]ddd.ddd,
| where the precision determines the number of digits after
| the decimal point.
G | Equivalent to `g', but use an uppercase `E' in exponent form.
g | Convert a floating point number using exponential form
| if the exponent is less than -4 or greater than or
| equal to the precision, or in d.dddd form otherwise.
i | Identical to `d'.
o | Convert argument as an octal number.
p | The valuing of argument.inspect.
s | Argument is a string to be substituted. If the format
| sequence contains a precision, at most that many characters
| will be copied.
u | Treat argument as an unsigned decimal number. Negative integers
| are displayed as a 32 bit two's complement plus one for the
| underlying architecture; that is, 2 ** 32 + n. However, since
| Ruby has no inherent limit on bits used to represent the
| integer, this value is preceded by two dots (..) in order to
| indicate a infinite number of leading sign bits.
X | Convert argument as a hexadecimal number using uppercase
| letters. Negative numbers will be displayed with two
| leading periods (representing an infinite string of
| leading 'FF's.
x | Convert argument as a hexadecimal number.
| Negative numbers will be displayed with two
| leading periods (representing an infinite string of
| leading 'ff's.


Examples:


   sprintf("%d %04x", 123, 123)               #=> "123 007b"
sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
sprintf("%u", -123) #=> "..4294967173"


Conditional validations

from here

  1. class User < ActiveRecord::Base
  2. validates_presence_of :password, :if => :should_validate_password?
  3. validates_presence_of :state, :on => :create
  4. validates_presence_of :state, :if => :in_us?

  5.  
  6. attr_accessor :updating_password
  7.  
  8. def in_us?
  9. country == 'US'
  10. end
  11.  
  12. def should_validate_password?
  13. updating_password || new_record?
  14. end
  15. end
  16.  
  17. # in controller
  18.  
  19. @user.updating_password = true

  20. @user.save
  21.  
  22. @user.save(false) # will avoid any validation in the model

Tuesday, April 1, 2008

time.strftime( string ) => string

from here



Formats time according to the directives in the given format
string. Any text not listed as a directive will be passed through to the
output string.



Format meaning:


  %a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character

t = Time.now
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003"
t.strftime("at %I:%M%p") #=> "at 08:56AM"


passing a variable to a partial

from here

Passing a variable to a partial means you can be clever about re-using your code to output different collections of data in the same way.



Essentially you just write:




<%= render :partial => '/path/to/_partial', :locals => { :items => @items } %>



The local variable items now makes each element of @items available in the partial. e.g.




<% for item in items -%>
do something...
<% end -%>

Wednesday, March 19, 2008

Password Validation

From: here
  • Users must supply a passphrase when signing up
  • Passphrases should be between 8 and 64 characters in length
  • It is not necessary to supply a passphrase when updating an existing record
  • Confirmation must be supplied when setting a new passphrase on an existing record

These requirements lead to the following validations:


  MINIMUM_PASSPHRASE_LENGTH     = 8
MAXIMUM_PASSPHRASE_LENGTH = 64

validates_presence_of  :passphrase,
 :on => :create
validates_length_of  :passphrase,
 :in => MINIMUM_PASSPHRASE_LENGTH..MAXIMUM_PASSPHRASE_LENGTH,
 :if => Proc.new { |u| !u.passphrase.blank? }
validates_confirmation_of  :passphrase,
 :if => Proc.new { |u| !u.passphrase.blank? }

Tuesday, March 18, 2008

Wma player embedding example


<object id="MediaPlayer" height=50 classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">
<param name="filename" value="http://ws.radley.org.uk/Public/Modern%20Languages/Deutsch/media/AQA_GCSE/AQA%202003%20specimen.wma">
<embed type="application/x-mplayer2" src="http://ws.radley.org.uk/Public/Modern%20Languages/Deutsch/media/AQA_GCSE/AQA%202003%20specimen.wma" name="MediaPlayer" width=600 height=50></embed>
</object>
<p>
Download paper <a href="http://ws.radley.org.uk/Public/Modern%20Languages/Deutsch/media/AQA_GCSE/papers/listen%202003%20spec.pdf" target="_blank">here</a>

Partial syntax

<%= render :partial => "signup_form" %>



This would render "_signupform.html.erb" and pass the instance variable @signup_form in as a local variable account to the template for display.

Monday, March 17, 2008

Ruby if else syntax


print "The variable is " + (var == 10 ? "10″ : "Not 10″)