Search

Resume and bio of the author Couple of articles related to my hobby - robotics
My impressions about immigration to Australia. In Russian only. Recipes for everyday problems solving
Linux-related posts Windows-related posts
Software-related posts A lot of info about hardware
Different tools you might find useful Posts about various web technologies
Everything that doesn't fit the rest of the menu RSS feed for this blog

Tag Cloud

Archives

Links

Andrey Mikhalchuk’s Blog

Technoblog about life

Nov 8, 2013 How to use large / multiline text as a field in mongodb

I’m working on a project that requires storing large multiline chunks of text in MongoDB. The chunks should be inserted in the database during initial database population, so I need to enter them somewhere in db population script. Unfortunately you can’t just put something like this:

db.tests.insert( {
name: 'test',
text: 'this is
my superawesome
multiline content'
} )

Javascript/JSON do not support multiline text like this. Fortunately there are several options that made my life easier. Here they are:

Mar 2, 2013 Don’t use valgrind on MacOS!

Subj,
It’s buggy and misleading. You will do better by installing Oracle Virtualbox (free) with Linux (free) and running valgrind (free) in the virtual machine.

Apr 24, 2008 MineStream Defender – the ultimate network security device

MineStream Defender - the ultimate network security deviceLast 12 months I was working on an interesting device that provides the network security features many companies and families are dreaming about. You probably already have heard about different threats out there like internet predators, viruses, spyware, dangerous websites, confidential information leaking from your business and others. Also you probably tried to find answers to questions like

  • Is my office network used appropriately? Do people really use it for work and not something else?
  • Are my kids safe in the Internet? Are their virtual friends really friends?
  • Why is my internet so slow?
  • Who in my network is using the internet most, when and what for?
  • How can I prevent my children or employees from browsing inappropriate content, wasting time in chats or games?

Finally, you might want to get answers to the questions immediately and you don’t want to spend a lot of time configuring every single computer in your network, installing software and other techi stuff … So the answer to all those questions is one small box called MineStream Defender and here is what it can do …

Jan 28, 2008 Simple free online IP conversion tool

For debugging purposes I frequently need to quickly convert ip addresses from one representation to another. Here is quick and dirty (I’ll cleanup the interface when get some free time) converter that does the job.
If you don’t see the form below because of some reason please proceed to this page.
The following formats are supported:

  • integer
  • unsigned integer
  • dot notation
  • hex number
  • binary number
  • octal number
  • natural netmask

Please specify one of the following

Convert from int:
Convert from dot notation:

function dec2string ($decimal, $base)
{
global $error;
$string = null;
$base = (int)$base;
if ($base < 2 || $base > 36 || $base == 10) {
echo ‘BASE must be in the range 2-9 or 11-36′;
exit;
}
$charset = ’0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$charset = substr($charset, 0, $base);
if (!ereg(‘(^[0-9]{1,16}$)’, trim($decimal))) {
$error['dec_input'] = ‘Value must be a positive integer’;
return false;
}
do {
$remainder = bcmod($decimal, $base);
$char = substr($charset, $remainder, 1); // get CHAR from array
$string = “$char$string”; // prepend to output
$decimal = bcdiv(bcsub($decimal, $remainder), $base);
} while ($decimal > 0);
return $string;
}

function string2dec ($string, $base)
{
global $error;
$decimal = 0;
$base = (int)$base;
if ($base < 2 || $base > 36 || $base == 10) {
echo ‘BASE must be in the range 2-9 or 11-36′;
exit;
}
$charset = ’0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$charset = substr($charset, 0, $base);
$string = trim($string);
if (empty($string)) {
$error[] = ‘Input string is empty’;
return false;
}
do {
$char = substr($string, 0, 1); // extract leading character
$string = substr($string, 1); // drop leading character
$pos = strpos($charset, $char); // get offset in $charset
if ($pos === false) {
$error[] = “Illegal character ($char) in INPUT string”;
return false;
}
$decimal = bcadd(bcmul($decimal, $base), $pos);
} while($string <> null);
return $decimal;
}

function pad( $str, $num )
{
return str_repeat( “0″, $num – strlen( $str ) ).$str;
}

// main
if( isset( $_GET["submit"] ) )
{
$ip = 0;
if( isset( $_GET["int"] ) && $_GET["int"] != “” )
{
$ip = $_GET["int"];
}
else if( isset( $_GET["dot"] ) && $_GET["dot"] != “” )
{
$ip = ip2long( $_GET["dot"] );
}
else
{
$ip = 0;
}

$uns_ip = ( $ip > 0 ? $ip : 0xffffffff + $ip + 1 ) + 0;

if( ( $uns_ip & 0×80000000 ) == 0 )
{
$mask = 0xff000000;
}
else if( ( $uns_ip & 0xC0000000 ) == -2147483648 )
{
$mask = 0xffff0000;
}
else if( ( $uns_ip & 0xE0000000 ) == -1073741824 )
{
$mask = 0xffffff00;
}
else
{
$mask = “”;
}
$dot_ip = long2ip( $uns_ip );
$hex_ip = dec2string( $uns_ip, 16 );
$hex_ip = “0x”.pad( $hex_ip, 8 );
$oct_ip = dec2string( $uns_ip, 8 );
$oct_ip = “0″.pad( $oct_ip, 16 );
$bin_ip = dec2string( $uns_ip, 2 );
$bin_ip = pad( $bin_ip, 32 );
?>

Conversion result

Dot notation
Decimal number
Unsigned decimal number
Hexadecimal number
Binary number
Octal number
Natural netmask

Site Map (c) Andrey Mikhalchuk, 2005-2008