Programming tricks tips, for programming languages like vb.net, python ,javascript, android framework
Tuesday, March 3, 2015
SamudBunShe Pro version 2.6
Monday, February 16, 2015
How to get latest version of btsync up to date in ubuntu
How to get latest version of btsync up to date in ubuntu
In Ubuntu, if you may want to use the Launchpad PPA instead of the default repositories. This is great and give your latest version without waiting default repositories updates.But the PPA only supports some Ubuntu versions for now
- lucid (10.04)
- precise (12.04)
- quantal (12.10)
- saucy (13.10)
- trusty (14.04)
And the PPA only supports the i386 and amd64 architectures. It could takes some hours for the packages to be published.
You can add the Launchpad PPA by put following commands:
sudo add-apt-repository ppa:tuxpoldo/btsync
sudo apt-get update
then make install / update by
sudo apt-get install btsync
Reference
https://launchpad.net/~tuxpoldo/+archive/ubuntu/btsync
Wednesday, January 21, 2015
Making tab page scroll with bootstrap
Making tab page scroll with bootstrap
1) first create tab.
<div class="scroller-shop scroller-left-shop"><i class="glyphicon glyphicon-chevron-left"></i></div>
<div class="scroller-shop scroller-right-shop"><i class="glyphicon glyphicon-chevron-right"></i></div>
<div class="wrapper-shop">
<ul class="nav nav-tabs list-shop" id="product-shop">
<img src="waiting.gif" />
</ul>
</div>
explanation
<div class="scroller-shop scroller-left-shop"><i class="glyphicon glyphicon-chevron-left"></i></div>
will display left arrow, when scroll
<div class="scroller-shop scroller-right-shop"><i class="glyphicon glyphicon-chevron-right"></i></div>
will display right arrow, when scroll
<div class="wrapper-shop">
<ul class="nav nav-tabs list-shop" id="product-shop">
<img src="waiting.gif" />
</ul>
</div>
will represent tab bar, it contain 2 pieces
<div class="wrapper-shop">
>> this one has the width that you want to see.
<ul class="nav nav-tabs list-shop" id="product-shop">
>> this one contains all tabs, and it will move during the scroll.
2. add Cascade style sheets
.wrapper-shop {
position:relative;
margin:0 auto;
overflow:hidden;
padding:5px;
height:50px;
}
.list-shop {
position:absolute;
left:0px;
top:0px;
min-width:3000px;
margin-left:12px;
margin-top:0px;
}
.list-shop li{
display:table-cell;
position:relative;
text-align:center;
cursor:grab;
cursor:-webkit-grab;
color:#efefef;
vertical-align:middle;
}
.scroller-shop {
text-align:center;
cursor:pointer;
display:none;
padding:7px;
padding-top:11px;
white-space:no-wrap;
vertical-align:middle;
background-color:#fff;
}
.scroller-right-shop{
float:right;
}
.scroller-left-shop {
float:left;
}
explanation
height:50px;
this is the height of the tab
height:50px;
this is the height of the tab
3) set function, and execute
setTimeout(function() {
//create the shop here
$('#product-shop').html('<li>tab1</li><li>tab2</li>');
setTimeout(function() {
//scroll
var itemslist={data:[],count:0}
var widthOfList = function(){
var itemsWidth = 0;
$('.list-shop li').each(function(){
var itemWidth = $(this).outerWidth();
itemsWidth+=itemWidth;
if (!itemslist['done']) itemslist['data'][itemslist['count']++]=$(this).position().left
});
itemslist['done']=1
return itemsWidth;
};
var getLeftPosi = function(){
return $('.list-shop').position().left;
};
var reAdjust = function(){
if (($('.wrapper-shop').outerWidth()) < widthOfList()) {
if ((Math.abs(getLeftPosi()) + $('.wrapper-shop').outerWidth()) > widthOfList()){
$('.scroller-right-shop').hide();
}else{
$('.scroller-right-shop').show();
}
}
else {
$('.scroller-right-shop').hide();
}
if (getLeftPosi()<0) {
$('.scroller-left-shop').show();
}
else {
$('.scroller-left-shop').hide();
}
}
//initial
reAdjust();
var newposition = function(pos0, type){
var pos = Math.abs(pos0)
for (var i=0;i<itemslist['data'].length;i++){
if (itemslist['data'][i] > pos){
if (type=='right'){
if (i == 0) return 0
//else
return '-'+itemslist['data'][i-1]
}else{
if (i == (itemslist['data'].length-1)) return itemslist['data'][itemslist['data'].length-1]
return '-'+itemslist['data'][i]
}
break;
}
}
return pos
}
$('.scroller-right-shop').off()
$('.scroller-right-shop').on('click', function() {
$('.scroller-left-shop').fadeIn('slow');
$('.scroller-right-shop').fadeOut('slow');
var pos= getLeftPosi() - $('.wrapper-shop').outerWidth()
pos = newposition(pos,'right')
$('.list-shop').animate({left:pos+"px"},'slow',function(){
reAdjust();
});
});
$('.scroller-left-shop').off()
$('.scroller-left-shop').on('click',function() {
$('.scroller-right-shop').fadeIn('slow');
$('.scroller-left-shop').fadeOut('slow');
var pos= getLeftPosi() + $('.wrapper-shop').outerWidth()
if (pos > 0) {
pos = 0
}else{
pos = newposition(pos,'left')
}
$('.list-shop').animate({left:pos+"px"},'slow',function(){
reAdjust();
});
});
},1500)
},1500)
explanation
setTimeout(function() {
$('#product-shop').html('<li>tab1</li><li>tab2</li>'); },1500)
we used the timer, so we can see waiting gif, show. and we load the tabs her.
setTimeout(function() {
},1500)
we used the other timer, so we will see the navigator show up later.
var widthOfList = function(){
var itemsWidth = 0;
$('.list-shop li').each(function(){
var itemWidth = $(this).outerWidth();
itemsWidth+=itemWidth;
if (!itemslist['done']) itemslist['data'][itemslist['count']++]=$(this).position().left
});
itemslist['done']=1
return itemsWidth;
};
this is to calculate the total width of the list, and collect each tab position (for case that you have each tab with different width)
itemslist
it will contain the position of each tab
var getLeftPosi = function(){
return $('.list-shop').position().left;
};
to get the position of tab bar
var reAdjust = function(){
if (($('.wrapper-shop').outerWidth()) < widthOfList()) {
if ((Math.abs(getLeftPosi()) + $('.wrapper-shop').outerWidth()) > widthOfList()){
$('.scroller-right-shop').hide();
}else{
$('.scroller-right-shop').show();
}
}
else {
$('.scroller-right-shop').hide();
}
if (getLeftPosi()<0) {
$('.scroller-left-shop').show();
}
else {
$('.scroller-left-shop').hide();
}
}
this function will used to validate to show left or right scroll button, if there total size of tab is small then we don't need to show the scroll button
of once it goes the left most, we don't need to show scroll left button, and it goes to the right most then we don't show scroll right button
var newposition = function(pos0, type){
var pos = Math.abs(pos0)
for (var i=0;i<itemslist['data'].length;i++){
if (itemslist['data'][i] > pos){
if (type=='right'){
if (i == 0) return 0
//else
return '-'+itemslist['data'][i-1]
}else{
if (i == (itemslist['data'].length-1)) return itemslist['data'][itemslist['data'].length-1]
return '-'+itemslist['data'][i]
}
break;
}
}
return pos
}
this function return the good position for display the move tab
$('.scroller-right-shop').off()
$('.scroller-right-shop').on('click', function() {
$('.scroller-left-shop').fadeIn('slow');
$('.scroller-right-shop').fadeOut('slow');
var pos= getLeftPosi() - $('.wrapper-shop').outerWidth()
pos = newposition(pos,'right')
$('.list-shop').animate({left:pos+"px"},'slow',function(){
reAdjust();
});
});
add event to scroll right button when click, we calculate new position and move the tabs to the left
$('.scroller-left-shop').off()
$('.scroller-left-shop').on('click',function() {
$('.scroller-right-shop').fadeIn('slow');
$('.scroller-left-shop').fadeOut('slow');
var pos= getLeftPosi() + $('.wrapper-shop').outerWidth()
if (pos > 0) {
pos = 0
}else{
pos = newposition(pos,'left')
}
$('.list-shop').animate({left:pos+"px"},'slow',function(){
reAdjust();
});
});
add event to scroll left button when click, we calculate new position and move the tabs to the right
setTimeout(function() {
$('#product-shop').html('<li>tab1</li><li>tab2</li>'); },1500)
we used the timer, so we can see waiting gif, show. and we load the tabs her.
setTimeout(function() {
},1500)
we used the other timer, so we will see the navigator show up later.
var widthOfList = function(){
var itemsWidth = 0;
$('.list-shop li').each(function(){
var itemWidth = $(this).outerWidth();
itemsWidth+=itemWidth;
if (!itemslist['done']) itemslist['data'][itemslist['count']++]=$(this).position().left
});
itemslist['done']=1
return itemsWidth;
};
this is to calculate the total width of the list, and collect each tab position (for case that you have each tab with different width)
itemslist
it will contain the position of each tab
var getLeftPosi = function(){
return $('.list-shop').position().left;
};
to get the position of tab bar
var reAdjust = function(){
if (($('.wrapper-shop').outerWidth()) < widthOfList()) {
if ((Math.abs(getLeftPosi()) + $('.wrapper-shop').outerWidth()) > widthOfList()){
$('.scroller-right-shop').hide();
}else{
$('.scroller-right-shop').show();
}
}
else {
$('.scroller-right-shop').hide();
}
if (getLeftPosi()<0) {
$('.scroller-left-shop').show();
}
else {
$('.scroller-left-shop').hide();
}
}
this function will used to validate to show left or right scroll button, if there total size of tab is small then we don't need to show the scroll button
of once it goes the left most, we don't need to show scroll left button, and it goes to the right most then we don't show scroll right button
var newposition = function(pos0, type){
var pos = Math.abs(pos0)
for (var i=0;i<itemslist['data'].length;i++){
if (itemslist['data'][i] > pos){
if (type=='right'){
if (i == 0) return 0
//else
return '-'+itemslist['data'][i-1]
}else{
if (i == (itemslist['data'].length-1)) return itemslist['data'][itemslist['data'].length-1]
return '-'+itemslist['data'][i]
}
break;
}
}
return pos
}
this function return the good position for display the move tab
$('.scroller-right-shop').off()
$('.scroller-right-shop').on('click', function() {
$('.scroller-left-shop').fadeIn('slow');
$('.scroller-right-shop').fadeOut('slow');
var pos= getLeftPosi() - $('.wrapper-shop').outerWidth()
pos = newposition(pos,'right')
$('.list-shop').animate({left:pos+"px"},'slow',function(){
reAdjust();
});
});
add event to scroll right button when click, we calculate new position and move the tabs to the left
$('.scroller-left-shop').off()
$('.scroller-left-shop').on('click',function() {
$('.scroller-right-shop').fadeIn('slow');
$('.scroller-left-shop').fadeOut('slow');
var pos= getLeftPosi() + $('.wrapper-shop').outerWidth()
if (pos > 0) {
pos = 0
}else{
pos = newposition(pos,'left')
}
$('.list-shop').animate({left:pos+"px"},'slow',function(){
reAdjust();
});
});
add event to scroll left button when click, we calculate new position and move the tabs to the right
Monday, January 19, 2015
SamudBunShe version 1.27
SamudBunShe Pro version 2.5
Thursday, January 15, 2015
How to sort string in javascript
How to sort string in javascript
example If you have an array of string, and you want to sort it.how to do ?
1. simple array
var pets = ['cat','snake','dog'];
pets.sort(function(a, b){
if (a > b)
return 1;
else if if (a.n == b.n)
return 0;
else
return -1;
});
your data will be sort like this
- cat
- snake
- dog
2. table data
if you have data like this table, you want to sort by name
| name | age |
| sammy | 12 |
| tony | 51 |
| lucy | 20 |
// fill in array
var ages_list = [];
ages_list.push({"name":"sammy","age",12});
ages_list.push({"name":"tony","age",51});
ages_list.push({"name":"lucy","age",20});
//sort it
ages_list.sort(function(a, b){
if (a.name > b.name)
return 1;
else if if (a.name == b.name)
return 0;
else
return -1;
})
this is result of sort
| name | age |
| lucy | 20 |
| sammy | 12 |
| tony | 51 |
Thursday, January 8, 2015
Detect timezone in javascript
Detect timezone in javascript
For now I'm working on a project, I need to display the value of date on screen. The value I received , I get it as datetime in UTC value. I need to display as local timezone.
var time_value = 1391187600000;
I check the current timezone by use this method getTimezoneOffset
It is a method of object date in javascript, it return number of minutes different from UTC.
This is what I use
var hplus = ((new Date().getTimezoneOffset()) / 60) * -1);
if (isNaN(hplus)) hplus = 0;
explanation:
new Date()
- Need to use method of object date, then create one
new Date().getTimezoneOffset()
- Receive -420 (minutes) from this method
(new Date().getTimezoneOffset()) / 60
- Need hour so I divided it by 60, in my sample I will get 7
(((new Date().getTimezoneOffset()) / 60) * -1)
- As I received UTC, to display I will add 7 to UTC hour, I prefer to get +7
- If you are at Arizona in USA, you will received -7
Wednesday, January 7, 2015
Check type of varaiable in javascript
Check type of varaiable in javascript
In javascript, you can get the type of variable in javascript with this function:
typeof(var)
example:
var a = 1;
>> typeof(a)
- return number
var b = "hello";
>> typeof(b)
- return string
var c = new Date();
>> typeof(c)
- return object
the sample of useful of this:
var man = {"name":"tom", "age" : 12};
if you want to display it according their type in table.
By String should align left, and number align right.
var html_table='<table><tr>';
for (var each in man){
html_table+='<td>'+each+'</td><td align="'
if (typeof(man[each])=='number') html_table+='right';
else if (typeof(man[each])=='string') html_table+='left';
html_table += '">'+man[each]+'</td>';
};
html_table+='</tr></table>';
after run, you will see the result like this
| name | tom |
| age | 12 |
Tuesday, January 6, 2015
Regular expression in javascript
Regular expression in javascript
example of the use, if you want to extract "my name" from this string '"name":"my name"'var ret = '"name":"my name"';
var rets = ret.match(/name[\\'"+]:[\\'"+]([^\0'"]+)/i)||[,];
you will get rets[0] = "name":"my name"
and you will get rets[1] = "my name"
explanation:
.match is the method of string type. this is actual structure .match(//i)
i -> indicate that we don't care the case
so if you have string = '"Name":"my name"' or '"nAme":"my name"' it will also work
now look at this regular expression
name >> begin of search
- we want to find the text that has "name" at the begin of the search
- your name : >> this will work
- your nnme : >> this will not work
[\\"'+] >> represent next characters after above word
- next character must be \ " or ', at least 1
- your name" : >> this will work
- your name: >> this will not work
- it can be more than 1
- your name"' :>> this will work
- your name\" :>> this will work
- your name": >> this will work
- your name""x >> this will not work
[\\"'+] >> represent next characters after above word
- next character must be \ " or ', at least 1
- your name":" >> this will work
- your name: " >> this will not work
- it can be more than 1
- your name"':" :>> this will work
- your name\":\" :>> this will work
([^\0'"]+) >> represent group of text that after above word
- it can be any character but not ascii 0 and not " and not '
- your name":"sss" :>> this will work
- your name":"sss :>> this will not work
- it can be more than 1
- your name":"s" :>> this will work
- your name":"sss" :>> this will work
let's look at the function method
ret.match(/name[\\'"+]:[\\'"+]([^\0'"]+)/i)
>> this will return array if match
>> and return null if not match
ret.match(/name[\\'"+]:[\\'"+]([^\0'"]+)/i) || [,]
>> always return array, if match will return matching array
>> if not match you will get empty array of 2 index
Friday, January 2, 2015
Happy New Year 2015
Happy New Year 2015
I wish all the reader the happiness, More trick and hint will coming.
regards
Monday, December 1, 2014
SamudBunShe Pro version is release.
SamudBunShe Pro version is release.
Now SamudBunShe Pro version is release. You may wonder what's different between Pro version and Free version.
| Free | Pro | |
| Country | Only Thailand | Worldwide |
| Backup | Yes | Yes |
| Restore | No | Yes |
The only different now between them are Free version is available only in Thailand, while Pro version is for worldwide.
Pro version has the restore and backup function, while Free version has only backup function.
The restore function is used for open and use the data from the backup function. So it will very helpful if you have make a big mistake, or you want to open the previous backup.
If you have a free version before, you make the backup from your free version. Once you install the Pro version, you go to restore function and browse the backup from free version.
After that you can continue to use your Pro. Or you can start from scratch.
Saturday, November 8, 2014
SQLite The free and powerful database for small usage with vb.net
Sqlite The free and powerful database for small usage
Are you looking for free database that you can use in your application ?
I would like to suggest your "SQLite" (download link) , after you install you will have this file "System.Data.SQLite.DLL" , this is all you need.
let's start.
1) you create normal window application., you will come to this screen look on your right.2) click on "show all files" icon
4) select "Browse" tab then select your file "System.Data.SQLite.DLL"
5) you will have reference appear., now your project is ready to use.
6) first , we need to create database. This is function to do.
7) after you run this function, you will have new file create (with zero byte because you have nothing yet)
8) second, we will have to create database structure with tables.
- we create connection (this function will be used for every time you want to connect to database)

- now we are ready., so let's create table (see more detail about field type here)

- next we insert some data
- now we have data ready in table,

Wednesday, March 9, 2011
Using style sheet to make text center with HTML
Using style sheet to make text center with HTML
in style sheet (.css) file , you define class like thisdiv.div_center{
width:800px;
left:50%;
margin: 0px auto 0px auto;
}
to use like this
...
<body>
<div class = "div_center">
... center stuff..
</div>
</body>
Tuesday, March 8, 2011
WPF Datagrid and datatable in vb.net
WPF Datagrid and datatable in vb.net
To assign datatable to WPF datagrid we simple use property "defaultview".
sample in vb.net:
dim mdt as new system.data.datatable
mdt.columns.add("Column1")
mdt.columns.add("Column2")
mdt.rows.add("id 1", "text 1")
mdt.rows.add("id 2","text 2")
mdt.rows.add("id 3","text 3")
mydatagrid.itemssource = mdt.defaultview
Monday, March 7, 2011
Important of the log file in programming
Important of the log file in programming
What's log file?
Log file is the file program create during it operation and process, this log file is very useful for developer to check and debug the big program.We can integrate log file very easy through the system.file.io
Sample in vb.net
Private mlogst as system.text.stringbuilder
'function to create log file.
Sub writelog(mlog as string)
Dim logfile as string = "c:\temp\log.txt"
Try
'mean there is previous log that didn't write, so we write it.
IO.File.AppendAllText(logfile,mlogst.tostring)
'after write we empty it.
mlogst = nothing
'write the log information..
IO.File.AppendAllText(logfile,mlog)
Catch ex as exception
'if there is error while write the log this time
If mlogst is nothing then mlogst = new system.text.stringbuilder
mlogst.apppend(mlog)
End sub
//// to use…
Sub main
Writelog ("starting program…")
Do …..
Writelog ("doing stuff…"
Do …
Writelog ("ending program..")
End sub
You can write more useful information , like the datetime of the log occur , current user that use this log..
IO.File.AppendAllText(logfile,mlog)
So you write as..
Io.file.appendalltext(logfile,string.concat(now , " " ,mlog))
You should have the log like this..
07-03-2011 6:35:01 PM starting program..
07-03-2011 6:35:02 PM doing stuff..
….
07-03-2011 6:36:01 PM ending program..
'mlogst is the cache in case that file is busy / can't write the information
'we can keep and write it later.
If not mlogst is nothing then
'mean there is previous log that didn't write, so we write it.
IO.File.AppendAllText(logfile,mlogst.tostring)
'after write we empty it.
mlogst = nothing
End if
'write the log information..
IO.File.AppendAllText(logfile,mlog)
Catch ex as exception
'if there is error while write the log this time
', we keep in the mlogst for write next time.
If mlogst is nothing then mlogst = new system.text.stringbuilder
mlogst.apppend(mlog)
End try
End sub
//// to use…
Sub main
Writelog ("starting program…")
Do …..
Writelog ("doing stuff…"
Do …
Writelog ("ending program..")
End sub
You can write more useful information , like the datetime of the log occur , current user that use this log..
IO.File.AppendAllText(logfile,mlog)
So you write as..
Io.file.appendalltext(logfile,string.concat(now , " " ,mlog))
You should have the log like this..
07-03-2011 6:35:01 PM starting program..
07-03-2011 6:35:02 PM doing stuff..
….
07-03-2011 6:36:01 PM ending program..
Sunday, March 6, 2011
Subscribe to:
Posts (Atom)









