How to use the iostat utility. There is much to say about IO monitoring and interpreting results.
let's talk about Bridgerton tea, my ask is open
Monterey Bay Aquarium
RMH

roma★
No title available
hello vonnie
Phantogram Three

bliss lane
I'd rather be in outer space 🛸

Game Changer & Make Some Noise

izzy's playlists!
Cosmic Funnies
taylor price

gracie abrams
No title available
almost home
tumblr dot com
Fai_Ryy
cherry valley forever
todays bird
seen from Iraq
seen from Germany
seen from Switzerland
seen from United Kingdom

seen from Singapore

seen from Malaysia
seen from Colombia
seen from United Kingdom
seen from Philippines
seen from Poland

seen from Brazil

seen from Colombia
seen from United States
seen from Malaysia
seen from United States

seen from Bulgaria
seen from Brazil

seen from Malaysia
seen from Brazil
seen from India
@simplicity-is-divine-blog
How to use the iostat utility. There is much to say about IO monitoring and interpreting results.
Nice explanation by Tomas Lane about Bitmap Indexes,...
Python 2.5 improvements...
This is my short list of python 2.5 improvements, just to have noted somewhere. It can be usefull if you use RHEL5 python 2.4 and RHEL 6 python 2.6.
conditional expressions
x = true_value if condition else false_value
functools module
import functools def log (message, subsystem): "Write the contents of 'message' to the specified subsystem." print '%s: %s' % (subsystem, message) ... server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket')
Absolute imports becomes default later, to import it in new code:
from __future__ import absolute_import
Also there is way to do relative imports
from .string import name1, name2
Unifying try-except and try-finally
try: block-1 ... except Exception1: handler-1 ... except Exception2: handler-2 ... else: else-block finally: final-block
Yield now is now expression not statement
You can use it.send(value) to send value to yield. yield will return None if nothing is given.
.close() -> GeneratorExit @yield .throw(type, value=None, traceback=None)() -> @yield
'with' statement
with expression [as variable]: with-block
You can also use contextlib to make closeable wrappers :).
import urllib, sys from contextlib import closing with closing(urllib.urlopen('http://www.yahoo.com')) as f: for line in f: sys.stdout.write(line)
ctypes
Module for transparent calling c functions from python code.
We hope we can illuminate why W3Schools is a troublesome resource, why their faulty information is a detriment to the web, and what you (and they) can do about it.
Nice to know
Nice interactive tutorial for VIM beginers. You may also try vim-adventures but you need to pay 25$ to play the game. It's nice one.
Hey I just signed up for GroupAngle . A new social shopping network. Join me. :)
FreeBSD & RVM are happy together
I had a problem with RVM installing ruby-1.9.3 because it expect for default make to be gnu make. So I propose simple sollution to link it like this:
ln -s /usr/local/bin/gmake ~/.rvm/bin/make
VIM, my list of what you need to know
I won't talk here about plugins, only basic VIM and how to use it to it's full strength. I can't emphasize enough that you need to know all of this to work fast in VIM.
Modes are hardest thing to get used to. You will know that you know VIM when you spend most of time in Normal mode. If you don't beleive me, than go ask Bram Moolenaar VIM creator.
This is not replacement for 'vimtutor', I just put all things that I use in day to day basis and think that are most important.
Normal mode - For moving over file content, removing, copying (yanking), pasting content. You can always get into this mode with few ESC clicks (one two exit Insert mode or Command mode).
One character movement:
j - down
k - up
h - left
l - right
Word movement:
w - one word right
b - one word left
Scrolling:
Ctrl+e - one line down scroll
Ctrl+y - one line up scroll
Ctrl+d - Half page down
Ctrl+u - Half page up
Special moves:
^ - Beginning of line
$ - End of line
gg - Beginning of text
G - End of text
Copy, Paste, delete:
dd - delete current line and also puths it into buffer
dw - delete word
d$ - delete everything to the end of line
p - paste whatever is in the buffer
yy - copy whole line
Visual mode:
With "v" from Normal mode, you can select any part of text and then with "d" to delete it or "y" to copy it. Use "V" if you want to select whole lines.
Go into Insert mode, from Normal mode:
i - Goes to insert mode at current character
a - After current char
A - Insert at end of line
o - Open new line after current one and goes to Insert mode
Insert mode - Here you do all typing stuff.
Ctrl+p - Dummy code complettion, it just looks at current open buffers and syntax similar text.
Ctrl+x Ctrl+o - Omni completion, it is smarter, and it is not always defined. Will talk about this latter.
Esc - Go to Normal mode
Command mode - Here you type all of commands. You go to this mode from Normal mode with ":", and then type some command. Most used commands are:
:q - Exit
:q! - Exit without save
:w - Save current file
:w - Save current buffer to "file_name" destination
:e - Opening file
:tabe - Opening file in new tab
:set number - Enumerate all lines in text, it is usefull when you need to find some compile error
:colorscheme desert - Use colorscheme desert. You can always use tab to see available colorschemes.
Don't use Insert mode for moving!!
Installing bugzilla, notes
> Bugzilla is server software designed to help you manage software development. I made this short notes based on my experience on installing [bugzilla](http://www.bugzilla.org/). If you follow this notes, you need to have '*mysql-server*' installed and '*apache2*'. Also for compiling some modules you need basic development tools, in [*debian*](http://www.debian.org) you can install them with following meta package '*build-essential*'. If you use *mysql* then you need'*mysql-dev*' package so *mysql* module can compile. If you want graphs you need to install '*gd*' library and devs packages for it. First we make http folder where you will put your http apps, you can choose any directory that you like. If your distribution use some other group for running apache change '*http*' to follow that. $ sudo mkdir /home/http $ sudo chown your_username.http /home/http Download bugzilla in appropriate folder. $ cd /home/http $ wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-4.0.2.tar.gz $ tar xzf bugzilla-4.0.2.tar.gz $ rm bugzilla-4.0.2.tar.gz $ mv bugzilla-4.0.2 bugzilla $ cd bugzilla Install needed modules, note that if you installed local::lib or cpanm, then disable them before you do this step with: *'eval $(perl -Mlocal::lib=--deactivate)'*. By default *install-module.pl* command installs all modules in *'./lib'* folder of local bugzilla directory. I really liked that, because I always prefer to mantain clean perl5 and to use something like [*cpanm*](https://metacpan.org/module/App::cpanminus) to install all extra modules. $ ./install-module.pl --all You can now change some parameters of your bugzilla app like dbname... I changed this in my localconfig file, please don't use empty password. # localconfig file, '...' are not part of content ... $db_name = 'bugzilladb'; $db_user = 'bugzilla'; $db_pass = ''; ... After that you need to setup mysql so your bugzilla app can work with it. $ mysql -u root -p CREATE DATABASE bugzilladb; CREATE USER 'bugzilla'@'localhost' IDENTIFIED BY ''; GRANT ALL ON bugzilladb.* TO 'bugzilla'@'localhost'; Edit you apache2 conf, for my distro([Arch](http://www.archlinux.org/)) it is file: '*/etc/httpd/conf/httpd.conf*'. Alias /bugzilla /home/http/bugzilla/ # so we can just type http://localhost/bugzilla/ # and not http://localhost/bugzilla/index.cgi DirectoryIndex index.cgi index.html # Allow executing CGI in this directory Options +ExecCGI # What files are executable *.cgi & *.pl AddHandler cgi-script .cgi .pl # Lots of distros just disables viewing everything outside DocumentRoot # directory. This option allows viewing this directory from apache Order allow,deny Allow from all After that just open in your browser 'http://localhost/bugzilla/'. There can be couple modules missing, if that is a case then just install them with '*install-module.pl*' command.
JRuby Swing and SWT examples
I found on internet some old examples of using Swing and SWT so I decided to put new ones that works :). This are just code examples, nothing more, for now.
First come Swing:
#!/usr/bin/env ruby #Load Java platform support using JRuby 0.9.1 and later syntax require 'java' JFrame = javax.swing.JFrame JLabel = javax.swing.JLabel JPanel = javax.swing.JPanel JButton = javax.swing.JButton BorderLayout = java.awt.BorderLayout Event = java.awt.event $_clickMeMode = true _frame = JFrame.new() _panel = JPanel.new() _panel.setLayout(BorderLayout.new()) _panel.setBackground(java.awt.Color::white) _frame.getContentPane().add(_panel) _frame.defaultCloseOperation = JFrame::EXIT_ON_CLOSE $_button = JButton.new("Click Me") $_text = JLabel.new("I'm a Simple Program") _panel.add(BorderLayout::CENTER, $_text) _panel.add(BorderLayout::SOUTH, $_button) $_button.addActionListener do |event| source = event.getSource() if (source == $_button) if ($_clickMeMode) $_text.setText("Button Clicked") $_button.setText("Click Again") $_clickMeMode = false else $_text.setText("I'm a Simple Program") $_button.setText("Click Me") $_clickMeMode = true end end end _frame.setTitle("Example") _frame.pack() _frame.setVisible(true)
"require 'java'" is something you should have every time when you work with some java code. Also you may notice that ActionListener is done with ruby block. This is just copy/paste with changes so it works in new jruby, so don't screem at me because of using all those global variables...
SWT example also imports swt.jar which you should download from swt website. I was amazed how simple this was :).
#!/usr/bin/env ruby require 'java' require 'swt.jar' module SWTTest include_class 'org.eclipse.swt.widgets.Display' include_class 'org.eclipse.swt.widgets.Shell' include_class 'org.eclipse.swt.widgets.Text' include_class 'org.eclipse.swt.SWT' display = Display.new shell = Shell.new(display); helloWorldTest = Text.new(shell, SWT::NONE) helloWorldTest.setText("Hello World SWT") helloWorldTest.pack shell.pack shell.open while (!shell.isDisposed) do if !display.readAndDispatch display.sleep end end display.dispose end
Autovivification in Perl5
I thought for a long time that if you use this code:
my $lists_ref; push @{ $lists_ref }, 'some_elem';
You will get some error. I knew about autovivification but I thought it works only for $lists_ref->[0] types of referencing.
I met and dark side of autovivification, if you are not carefull, you may create elements in hash that you don't want, and then some code that use exists for some internal logic may break. You will need a lot of time to see that bug. One more thing in my list of Perl5 idiocracies.
Smart::Comments, make your life easier
This is most usefull module that I used in long time. You can get rid of all print statements that you used to track your flow. Now you embed them in comments and use them on need. You can have many levels of comments so you could add verbosity or remove it.
Do cpanp install Smart::Comments to live :).
use Smart::Comments; my $var = suspect_value(); ### got: $var ### Now computing value... # and when looping: #!!! Next examples gives you progress bar, how nice :) for my $big_num (@big_nums) { ### Factoring... done factor($big_num); } while ($error > $tolerance) { ### Refining---> done refine_approximation() } for (my $i=0; $i<$MAX_INT; $i++) { ### Working===[%] done do_something_expensive_with($i); }
JavaScript Perl One Liner beautifier
Just using cpan module I did one Perl one liner, here it is:
$ alias jsb='perl -MJavaScript::Beautifier=js_beautify -e \ "local $/;print js_beautify(<>)"'
You can put in your "~/.bashrc" file and use it in folowing way:
$ jsb input.javascript | less $ cat javacripts_file | jsb | less
rubyproblems.com Geography problem SOLVED :)
You can find whole problem on following [link](http://www.rubyproblems.com/problems/2010/04/geography_lesson). I used _ruby1.9_ which supports regex named capturing, that made a code much more readable. This is source code of class that does parsing: #!/usr/bin/env ruby1.9.1 class CoordinatesParser attr_reader :x_coordinates, :y_coordinates SIGN = %r{[+-]} SIDES_OF_WORLD = %r{[WESN]} DECIMAL = %r{\d+ \. \d+}x ### ### Regex for parsing all numeric formats ### @@DEGREES_REGEX = %r{ (?: (? (? \d+) \s+ (?\d+) \s+ (? #{DECIMAL})) | (? (? \d+) \s+ (? #{DECIMAL})) | (? #{DECIMAL}) )}x ### ### Regex for parsing all possible coordinates formats ### @@LONGITUDE_REGEX = %r{^ \s* (?# if we have *before* sides notation) (?#{SIDES_OF_WORLD})? \s* (?#{SIGN})? (? #{@@DEGREES_REGEX}) \s* (?# middle side is *always* there ) (?#{SIDES_OF_WORLD})? \s+ (?#{SIGN})? (? #{@@DEGREES_REGEX}) \s* (?# if we have *after* sides notation) (?#{SIDES_OF_WORLD})? $}xi def initialize data match_data = @@LONGITUDE_REGEX.match(data) @y_coordinates = parse_number( match_data[:l_number] ) @x_coordinates = parse_number( match_data[:r_number] ) parse_signs match_data do |x_sign, y_sign| @x_coordinates = @x_coordinates * x_sign @y_coordinates = @y_coordinates * y_sign end end private def parse_number degrees match_data = @@DEGREES_REGEX.match(degrees) if match_data[:decimal] degrees.to_f elsif match_data[:minutes] match_data[:d].to_f \ + match_data[:m].to_f / 60.0 elsif match_data[:seconds] match_data[:d].to_f \ + match_data[:m].to_f / 60.0 \ + match_data[:s].to_f / 3600.0 else nil end end def parse_signs match_data, &block x_sign = 1 y_sign = 1 if match_data[:m_side] if match_data[:b_side] y_sign = -1 if match_data[:b_side] == ?S x_sign = -1 if match_data[:m_side] == ?W elsif match_data[:a_side] y_sign = -1 if match_data[:m_side] == ?S x_sign = -1 if match_data[:a_side] == ?W else # Raise exception, bad data end elsif match_data[:l_sign] or match_data[:r_sign] y_sign = -1 if match_data[:l_sign] == '-' x_sign = -1 if match_data[:r_sign] == '-' end block.call(x_sign, y_sign) end end And everything was tested with this few simple tests: #!/usr/bin/env ruby1.9.1 require_relative 'coordinates_parser.rb' require 'test/unit' class TestCoordinatesParser < MiniTest::Unit::TestCase def test_parse_number cparser = CoordinatesParser.new('45.1234 36.2345') assert_equal( cparser.y_coordinates, 45.1234 ) assert_equal( cparser.x_coordinates, 36.2345 ) cparser = CoordinatesParser.new('40 30.6 65 36.36') assert_equal( cparser.x_coordinates, 65.606 ) assert_equal( cparser.y_coordinates, 40.51 ) cparser = CoordinatesParser.new('45 45 4.5 38 30 10.8') assert_equal( cparser.y_coordinates, 45.75125 ) assert_equal( cparser.x_coordinates, 38.503 ) end def test_signs_parsing cparser = CoordinatesParser.new('-45.1234 -36.2345') assert_equal( cparser.y_coordinates, -45.1234 ) assert_equal( cparser.x_coordinates, -36.2345 ) cparser = CoordinatesParser.new('45.1234 -36.2345') assert_equal( cparser.y_coordinates, 45.1234 ) assert_equal( cparser.x_coordinates, -36.2345 ) cparser = CoordinatesParser.new('-45.1234 36.2345') assert_equal( cparser.y_coordinates, -45.1234 ) assert_equal( cparser.x_coordinates, 36.2345 ) cparser = CoordinatesParser.new('N 40 30.6 E 65 36.36') assert_equal( cparser.y_coordinates, 40.51 ) assert_equal( cparser.x_coordinates, 65.606 ) cparser = CoordinatesParser.new('S 40 30.6 E 65 36.36') assert_equal( cparser.y_coordinates, -40.51 ) assert_equal( cparser.x_coordinates, 65.606 ) cparser = CoordinatesParser.new('N 40 30.6 W 65 36.36') assert_equal( cparser.y_coordinates, 40.51 ) assert_equal( cparser.x_coordinates, -65.606 ) cparser = CoordinatesParser.new('40 30.6 N 65 36.36 E') assert_equal( cparser.y_coordinates, 40.51 ) assert_equal( cparser.x_coordinates, 65.606 ) cparser = CoordinatesParser.new('40 30.6 S 65 36.36 E') assert_equal( cparser.y_coordinates, -40.51 ) assert_equal( cparser.x_coordinates, 65.606 ) cparser = CoordinatesParser.new('40 30.6 N 65 36.36 W') assert_equal( cparser.y_coordinates, 40.51 ) assert_equal( cparser.x_coordinates, -65.606 ) cparser = CoordinatesParser.new('N 45 45 4.5 W 38 30 10.8') assert_equal( cparser.y_coordinates, 45.75125 ) assert_equal( cparser.x_coordinates, -38.503 ) end end O beautiful Ruby :).
Enumerator in Ruby
Creating Enumerator object with `Kernel.enum_for( :method, *args )`. Takes values with using `method` suplied with `*args`.
irb(main):001:0> enum_obj = 'Hello my friend'.enum_for(:each_char) => # irb(main):002:0> enum_obj.select {|c| c =~ /[[:upper:]]/} => ["H"] irb(main):003:0> enum_obj.select {|c| c =~ /[[:lower:]]/} => ["e", "l", "l", "o", "m", "y", "f", "r", "i", "e", "n", "d"]
Even better stuff is yielder, here comes complex example.
triangular_numbers = Enumerator.new do |yielder| number = 0 count = 1 loop do number += count count += 1 yielder.yield number end end
First we make enumerator that generates triangle numbers. If we do something like `triangular_numbers.each {|n| puts n}` we will get unlimited output. But if we do `triangular_numbers.first(10) {|n| puts n}` we get first 10 numbers. But what if we want to select first 10 numbers using some other criteria. We could do something like this:
def infinite_select(enum, &block) Enumerator.new do |yielder| enum.each do |value| yielder.yield(value) if block.call(value) end end end p infinite_select(triangular_numbers) {|val| val % 10 == 0}.first(10)
This produce another Enum object, which produces values only if they conforms with some predetermined criteria.