I have a HP laptop and I use ubuntu 9.04. I was facing problem to adjust the brightness of the screen through fn+F7 or fn+F8 keys. I found the solution at http://ubuntuforums.org/showthread.php?t=673946. It should be noted here that it worked after restarting my laptop.
26 December 2009
Problem in adjusting brightness in HP laptop using ubuntu
Posted by আলোর ছটা at 9:01 PM 0 comments
Labels: ubuntu
21 December 2009
Problem with audio callback at skype in ubuntu
Solution:
- Go to "Options" (Ctrl+O)
- Click on "Sound Devices"
- Select "pulse" for both "Sound Out" and "Ringing"
- For "Sound In", you have to choose your appropriate option. Change the value for "Sound In" and test the sound by clicking on "Make a test call" and following the directions.
Posted by আলোর ছটা at 11:25 PM 1 comments
20 December 2009
How to shrink image size in ubuntu?
* Use imagemagick (sudo apt-get install imagemagick)
* If it is just one directory worth of images use
mogrify -resize 1024x1024 *.jpg
or
mogrify -resize 25% *.JPG
For more information, http://ubuntuforums.org/archive/index.php/t-518662.html
Posted by আলোর ছটা at 3:06 AM 0 comments
08 October 2009
C# : Dynamically adding control with docking works in reverse way
for (int i = 0; i < 5; i++)
{
Label l = new Label();
l.Text = "Label" + (i + 1);
l.Dock = DockStyle.Top;
panel1.Controls.Add(l);
}
The fact is the first control is being drawn at the bottom. So, I solved it with the help of Controls.SetChildIndex() function in the following way.
Solution:
for (int i = 0; i < 5; i++)
{
Label l = new Label();
l.Text = "Label" + (i + 1);
l.Dock = DockStyle.Top;
panel1.Controls.Add(l);
panel1.Controls.SetChildIndex(l, 0);
}
Improved Solution:
In the given solution, what actually happens is that the new control is added at the top (for the style Dock.Top), then it is moved to the bottom. But this change in position may cause unwanted blinking of UI. To avoid this unwanted situation, follow the following steps
- Add the new control with size (0,0)
- Change its index to 0 (upper solution)
- Resize again the control to actual size
for (int i = 0; i < 5; i++)
{
Label l = new Label();
l.Text = "Label" + (i + 1);
l.Dock = DockStyle.Top;
addControlInContainer(panel1, l);
}
public static void addControlInContainer(Control container, Control control)
{
// save actual size
Size tempSize = control.Size;
// Add the new control with size (0,0)
control.Size = new Size(0, 0);
container.Controls.Add(control);
// Change its index to 0
container.Controls.SetChildIndex(control, 0);
// Resize the control to actual size
control.Size = tempSize;
}
Posted by আলোর ছটা at 6:52 PM 0 comments
31 August 2009
Flash for beginners
Just install Adobe Flash CS3. And follow the tutorials below.
- Beginning Game Programming with Flash (Lakshmi Prayaga & Hamsa Suri) : If you are a stranger to CS3, if you cannot even draw object in CS3, then you'll find it useful.
- ActionScript 3.0 Game Programming University (Gary Rosenzweig) : It is a very nice tutorial, specially for programmers.
Posted by আলোর ছটা at 3:20 PM 0 comments
Labels: Flash
25 August 2009
Big Integer Arithmetics Library in JavaScript
- BigInt.add(n1, n2) returns n1+n2
- BigInt.subtract(n1, n2) returns n1-n2 [n1 must be greater than n2]
- BigInt.multiply(n1, n2) returns n1xn2
- BigInt.dividefunction(n1, n2) returns n1/n2 (integer part only)
- BigInt.remainder(n1,n2) returns n1%n2
- BigInt.isALessThanB(a,b) returns a <>
var BigInt =
{
add : function(n1, n2)
{
if(!this.isValidBigInt(n1) || !this.isValidBigInt(n2))
throw "Not a big integer.";
// make all input to string
n1 = n1 + "";
n2 = n2 + "";
var i;
var sum = "";
// reverse them for comfortable indexing
n1 = this.reverse( this.removeLeading0s(n1));
n2 = this.reverse(this.removeLeading0s(n2));
// make both of same length
var large = n1;
var small = n2;
if(n1.length<>
{
large = n2;
small = n1;
}
// pad with 0's
for(i=small.length; i
small += "0";
// start adding
var carry = 0;
for(i=0; i
{
var subSum = this.digitAt(small, i) + this.digitAt(large, i) + carry;
if(subSum <>
{
sum += (subSum + "");
carry = 0;
}
else
{
sum += (subSum - 10) + "";
carry = 1;
}
}
if(carry == 1)
sum += "1";
return this.removeLeading0s(this.reverse(sum));
},
subtract : function (n1, n2)
{
// n1: larger number
// n2: smalelr number
// returns n1 - n2
if(!this.isValidBigInt(n1) || !this.isValidBigInt(n2))
throw "Not a big integer.";
// make all input to string
n1 = n1 + "";
n2 = n2 + "";
var i;
var large = n1;
var small = n2;
large = this.reverse(large);
small = this.reverse(small);
// pad with 0's
for(i=small.length; i
small += "0";
var carry = 0;
var result = "";
for(i=0; i
{
var upDigit = this.digitAt(large,i);
var downDigit = this.digitAt(small, i);
var diff = upDigit - downDigit - carry;
if(diff >= 0)
{
result += (diff + "");
carry = 0;
}
else
{
result += (diff + 10 + "");
carry = 1;
}
}
return this.removeLeading0s( this.reverse(result) );
},
multiply : function(n1, n2)
{
// returns n1 * n2
// make all input to string
n1 = n1 + "";
n2 = n2 + "";
if(!this.isValidBigInt(n1) || !this.isValidBigInt(n2))
throw "Not a big integer.";
var mul = "";
var extra0s = "";
for(var i=n2.length-1; i>=0; i--)
{
var d = this.digitAt(n2,i);
var subMul = this.multiplyByOneDigit(n1, d);
if(i==n2.length-1)
{
mul = subMul;
}
else
{
extra0s += "0";
subMul += extra0s;
mul = this.add(mul, subMul);
}
}
return this.removeLeading0s(mul);
},
divide : function(n1, n2)
{
// returns Math.floor(n1/n2)
// make all input to string
n1 = n1 + "";
n2 = n2 + "";
if(!this.isValidBigInt(n1) || !this.isValidBigInt(n2))
throw "Not a big integer.";
n1 = this.removeLeading0s(n1);
n2 = this.removeLeading0s(n2);
var i;
var divisor = n2;
var result = "";
var rem = "";
for(i=0; i
{
rem += (n1[i]+"");
var iRem = rem;
if(this.isALessThanB(iRem, divisor))
{
result += "0";
}
else
{
var subDiv = this.shortDivide(iRem, divisor) + "";
result += (subDiv + "");
rem = this.subtract(iRem, this.multiply(subDiv, divisor));
}
}
return this.removeLeading0s(result);
},
isALessThanB : function (a,b)
{
if(!this.isValidBigInt(a) || !this.isValidBigInt(b))
throw "Not a big integer.";
// make all input to string
a = a + "";
b = b + "";
a = this.removeLeading0s(a);
b = this.removeLeading0s(b);
if(a.length != b.length)
return a.length <>
for(var i=0; i
{
var dA = this.digitAt(a,i);
var dB = this.digitAt(b,i);
if(dA != dB)
return dA <>
}
return false;
},
remainder : function(n1,n2)
{
// returns n1 % n2
// make all input to string
n1 = n1 + "";
n2 = n2 + "";
var d = this.divide(n1,n2);
return this.subtract(n1, this.multiply(d,n2));
},
shortDivide : function(a, b)
{
// a is less than 10b
var i=0;
while(!this.isALessThanB(a,b))
{
a = this.subtract(a,b);
i++;
}
return i;
},
multiplyByOneDigit : function (n, d)
{
// n: string
// d: number (0-9)
var n = this.reverse(n);
var carry = 0;
var result = "";
for(var i=0; i
{
var m = this.digitAt(n, i) * d + carry;
result += (m%10 + "");
carry = Math.floor(m/10);
}
if(carry > 0)
result += (carry + "");
return this.reverse(result);
},
reverse : function(s)
{
var iLen = s.length;
var strRev = "";
for(var i=iLen-1; i>=0; i--)
strRev += s.charAt(i);
return strRev;
},
digitAt : function(s, i)
{
var c = s[i];
return parseInt(c);
},
removeLeading0s : function(n)
{
n = n + "";
var result = "";
var i=0;
while(n[i] == '0')
i++;
if(i
{
result = n.substr(i);
}
if(result == "")
result = "0";
return result;
},
isValidBigInt : function(n)
{
if(typeof n != "string" && typeof n != "number")
return false;
// make it string (from both number & string)
n = n+"";
if(n.length == 0)
return false;
// check all digits
for(var i=0; i
if(n[i] < '0' || n[i] > '9')
return false;
return true;
}
};
var num1 = "26093683160935360286936021";
var num2 = "4864306873315646901285";
var resAdd = BigInt.add(num1, num2);
var resSub = BigInt.subtract(num1, num2);
var resMul = BigInt.multiply(num1, num2);
var resDiv = BigInt.divide(num1, num2);
var resRem = BigInt.remainder(num1, num2);
var resLess = BigInt.isALessThanB(num1, num2);
Posted by আলোর ছটা at 1:05 AM 0 comments
Labels: JavaScript