valgrind --tool=massif ./myprogram
The result is a massiv.out.
ms_print massif.out.0000 | less
This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.
sudo aptitude install linux-kernel-headers linux-headers-`uname -r`
set hostlist=(`cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | cut -f 1 -d ',' | uniq`)
complete ssh 'p/1/$hostlist/' 'p/2/c/'
# start ssh agent if not started yet
set SSH_ENV = "$HOME/.ssh/environment"
unset SSH_AGENT_RUNNING
if (-f $SSH_ENV) then
source $SSH_ENV
ps $SSH_AGENT_PID > /dev/null && set SSH_AGENT_RUNNING
endif
if ($?prompt && ! $?SSH_AGENT_RUNNING) then
echo "Initializing SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >! $SSH_ENV
chmod 600 $SSH_ENV
source $SSH_ENV
echo "done: ssh-agent is now running, PID $SSH_AGENT_PID"
/usr/bin/ssh-add
endif
VBoxManage setextradata "backlinux" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCPThen I followed the suggestion of Sebastian Bauer's blog: I installed the ntwind software's hidden start tool (homepage) and created two one-liner batch files that I use to start and stop the virtual machine. There are also more sofisticated approaches to run the machine as a windows service, however I found this very simple and I chose it for this reason.
VBoxManage setextradata "backlinux" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata "backlinux" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222
"c:\Program Files\standalone\hstart\hstart" /NOCONSOLE ""c:\Program Files\Sun\VirtualBox\vboxheadless" -s backlinux -vrdp off"
"c:\Program Files\Sun\VirtualBox\VBoxManage.exe" controlvm backlinux savestate
"c:\Program Files\Sun\VirtualBox\VBoxManage.exe" modifyhd backlinux.home.vdi --type writethrough
c /C vboxsfAs last step, I created two icons starting from NewTux.svg of Wikimedia Commons (author: Larry Ewing). I resized it to a 48px square and overlayed a green triangle (start icon) and a red square (stop icon). I created then links to my batch files to my desktop and assigned the icons to the links.
<?xml version="1.0"?>My settings are: ffmpeg encoding, mp4 container format, aac stereo sound, 50% constant quality, resize to 400px width. Note that to be able to create a preset under Vista you need to start the application with administrative rights.
<ArrayOfPreset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Preset>
<Level>0</Level>
<Name>Mobile phone</Name>
<Query> -f mp4 -w 400 -e ffmpeg -q 0.5 -a 1 -E faac -B 160 -R 0 -6 stereo -D 1 -m -v </Query>
</Preset>
</ArrayOfPreset>
export GREP_OPTIONS='--color=auto'
set lang=enThen I changed the startmenu entry to point to the bat file instead of the exe file (other settings: execute minimized, use icon of the .exe file).
start gimp-2.6.exe
git diff-tree <commit> -p --pretty > <filename>You can also use git format-patch, but that is more specialized for patches to be submitted by email.
git apply <filename>Here is an excerpt from the git diff-tree manual page:
When "git-diff-index", "git-diff-tree", or "git-diff-files"
are run with a -p option, "git diff" without the --raw option,
or "git log" with the "-p" option, they do not produce the output
described above; instead they produce a patch file. You can
customize the creation of such patches via the GIT_EXTERNAL_DIFF
and the GIT_DIFF_OPTS environment variables
edge.column=80This is an excerpt of the SciTE documentation for the edge property:
edge.mode=1
edge.colour=#C0DCC0
Indicates long lines. The default edge.mode, 0, does not
indicate long lines. An edge.mode of 1 uses a vertical
line to indicate the specified column and an edge.mode
of 2 changes the background colour of characters beyond
that column. For proportional fonts, an edge.mode of 2
is more useful than 1.
d/u | Move half page forward / backward |
20g | Move to line 20 |
20% | Move to the 20% point |
ma/'a | set markpoint "a" / move to markpoint "a" (also instead of "a" any other lowcase letter) |
/pattern | search pattern forward |
?pattern | search pattern backward |
n | next match |
N | previous match |
/!pattern | search non-matching line |
Esc-u | turn match highlighting on/off |
= | show info about the file and current position |
! command | execute command and show its output |
s filename | save to file (if the input was a pipe) |
and no particular settings regarding colors in <repository>/.git/config
[color]
diff = auto
status = auto
branch = auto
log = auto
-r or --raw-control-chars
Causes "raw" control characters to be displayed.
[...] Warning: when the -r option is used, less cannot
keep track of the actual appearance of the screen
(since this depends on how the screen responds to
each type of control character). Thus, various display
problems may result, such as long lines being split
in the wrong place.
-R or --RAW-CONTROL-CHARS
Like -r, but only ANSI "color" escape sequences are
output in "raw" form. Unlike -r, the screen appearance
is maintained correctly in most cases. [...]
class SuffixArray
attr_reader :suf, :string
def initialize(string)
@string = string
@suf = (0..string.size-1).sort_by{|i|@string[i..-1]}
end
end
namespace :db do
desc "Count distinct values for each non empty column of a table (TABLE=xxx) "+
"optionally using a condition (WHERE=\"yyy\")"
task :count_distincts => :environment do
raise "Specify option TABLE=<table_name>" unless ENV["TABLE"]
puts "Distinct values in table #{ENV['TABLE']}:"
puts "(condition: where #{ENV['WHERE']})" if ENV['WHERE']
c = ActiveRecord::Base.connection
columns = c.select_all("describe #{ENV['TABLE']};").map{|a|a["Field"]}
columns.each do |col|
sql = "select count(distinct #{col}) as c from #{ENV['TABLE']}"
sql << " where #{ENV['WHERE']}" if ENV['WHERE']
n = c.select_one(sql)['c']
puts "#{col}: #{n}" unless n == "0"
STDOUT.flush
end
end
end
int sqrt(int num) {
int op = num;
int res = 0;
int one = 1 << 14; // The second-to-top bit is set: 1L<<30 for long
// "one" starts at the highest power of four <= the argument.
while (one > op)
one >>= 2;
while (one != 0) {
if (op >= res + one) {
op -= res + one;
res += one << 1;
}
res >>= 1;
one >>= 2;
}
return res;
}
(from Wikipedia)
create_table :entities do |t|t.string :typeend
t.string :title
t.string :first_name
t.string :last_name
t.binary :logo
def method(a, b=0)but this isn't:
#...
end
Proc.new {|a, b=0| } ### syntax error!See e.g. this discussion in Ruby forum.
def a(b, c=1)
:lambda do |*args| # simulated signature: |b, c=1|This has the disadvantage that is not validating the number of arguments, so let's add some validation code to the block:
b, c = args[0], args[1] || 1
end
lambda do |*args| # simulated signature: |b, c=1|Now the block behaves like if it had the signature |b, c=1|.
b, c = args[0], args[1] || 1
# validate number of arguments:
err = "wrong number of arguments"
if args.size > 2
raise ArgumentError, "#{err} (#{args.size} for 2)"
elsif args.size == 0
raise ArgumentError, "#{err} (0 for 1)"
end
end
config.columns[].sort_by :sql
.ActiveScaffold::DataStructures::Column
adef sort_as_lob(lenght = 50, offset = 1)which I use on LOBs column declaring in the active scaffold config block:
sort_by :sql => "dbms_lob.substr(#{name},"+
"#{lenght},"+
"#{offset})"
end
active_scaffold do |config|
config.columns[:my_lob].sort_as_lob
end
class MyObject < ActiveRecord::BaseWell, "another object" can now be in any other table of the DB, and in the
belongs_to :another_object, :polymorphic => true
end
my_objects
table there are two columns (assuming you followed the conventions) named another_object_id
and another_object_type
, the first one containing the ID of the object, the second the model name. case
was introduced in the standard, if I am not wrong, in the SQL-92 version. I think that most SQL-DBs comply, SQL-Lite probably excluded (I tested only on Oracle). #You can use this sort_by_sql() method in the
# e.g. types = %w[Cat Dog Mouse]
#
def sort_by_sql(types)
sql = '(case (another_object_type)'
sql << types.map do |type|
'when #{type}
then (select label
from #{type.tableize} t
where t.id = another_object_id) '
end.join('')
sql << 'end)'
end
private :sort_by_sql
:order_by => sort_by_sql(...)
key of the find method to sort by the label method of the polymorphic association with only one query. This was sensibly faster in my case. AllowedTypes = %w[Cat Dog Mouse]That worked fine for me.
def self.sort_by_sql(types)
#...the code up here...#
end
active_scaffold :my_objects do |config|
# ...
config.columns[:another_object].sort_by :sql =>
sort_by_sql(*AllowedTypes)
# ...
end
task :one => [:two, :three]
desc "This task executes task two in its code!"
task :one do
# ... do domething
ENV['PAR1'] = 'xxx'
ENV['PAR2'] = 'yyy'
Rake::Task[ "two" ].execute
# ... do something
end
rake two PAR1 = xxx, PAR2 = yyy
namespace(:db) do
namespace(:pretend) do
desc "Pretend the database migrated 1 step or to VERSION=<nn>"
task :migrate => :environment do
c = ActiveRecord::Base.connection
if ENV['VERSION']
version = ENV['VERSION'].to_i
else
version = c.select_one("select version from schema_info")['version'].to_i + 1
end
c.execute("update schema_info set version = #{version}")
puts "Current version: #{version}"
end
desc "Pretend that the last migration did not happen"
task :rollback => :environment do
c = ActiveRecord::Base.connection
version = c.select_one("select version from schema_info")['version'].to_i - 1
c.execute("update schema_info set version = #{version}")
puts "Current version: #{version}"
end
end
end
require 'active_record/connection_adapters/oracle_adapter'
module ActiveRecord
module ConnectionAdapters
class OracleAdapter
# Returns an array of arrays containing the field values.
# Order is the same as that returned by #columns.
def select_rows(sql, name = nil)
result = select(sql, name)
result.map{ |v| v.values}
end
end
end
end
int main (int argc, char *argv[])
{
char * string;
long int number;
/* are there really 2 parameters? */
if (argc != 3) exit(EXIT_FAILURE);
/* catch them */
string = argv[1];
number = atoi(argv[2]);
/* use them */
printf("String parameter: %s\n",string);
printf("Number parameter+1: %d\n",number+1);
}