Sep 29 2015

Error: can’t use sharded collection from db.eval

As the title says. This error occurs when you try to use db.eval in a sharded collection. I find it when I tried to run my saved js function in mongoDB.

For me, instead of using db.eval, i tried using db.loadServerScripts();. And whola, it is solved db.eval problem.

Here is my code:

db.system.js.save({
    _id: “testread”,
    value: function (user_id) {
        return get_users_detail = db.getCollection(‘wp_users’).findOne({ID:user_id});

    }
});

db.loadServerScripts();
testread(1);

//db.eval(“testread(1);”);//error eval

Hope this simple tips can help you solve your db.eval error on sharded collection.


Sep 21 2015

Install Go Programming Language in Ubuntu

I know that Go Lang is not a new programming language. However, The reason I write down this is for me to easily remember the How To that I find in the internet. And to make me easier to do it again in the future.

  • Run apt-get to install Go Lang

sudo apt-get install golang

  • Set Go path:

mkdir -p ~/go;
echo “export GOPATH=$HOME/go” >> ~/.bashrc;
echo “export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin” >> ~/.bashrc;

  • Create directory src/github.com/user/hello inside your $home/go directory.

exp: /home/user/go/src/github.com/user/hello

  • Create a file hello.go inside /home/user/go/src/github.com/user/hello
  • Edit the file and put your code

exp:

package main

import “fmt”

func main() {
    fmt.Println(“hello world”)
}

  • Compile

$ go install github.com/user/hello

  • Run

$ $GOPATH/bin/hello

I hope this tips can help anyone who want to install Go Programming Language in Ubuntu.

 

Source:

https://github.com/ethereum/go-ethereum/wiki/Installing-Go

https://golang.org/doc/install


May 4 2012

Add New Virtual Host XAMPP or LAMPP on Linux

In this article, I would like to give a tutorial to Add New Virtual Host XAMPP or LAMPP on Linux.

In this case, I assume you already install xampp on your linux. Then lets start to Add New Virtual Host XAMPP or LAMPP on Linux immediately.

  1. Open your terminal and log as SU
  2. Type in your terminal “gedit /opt/lampp/etc/httpd.conf” to open httpd.conf in your text editor
    • delete “#” in front of “Include etc/extra/httpd-vhosts.conf” line
  3. Type in your terminal “gedit /opt/lampp/etc/extra/httpd-vhosts.conf” to edit httpd-vhosts.conf
    • add lines :

      <VirtualHost *:80>
      DocumentRoot /opt/lampp/htdocs
      ServerName localhost
      ServerAlias www.localhost
      </VirtualHost>

      <VirtualHost *:80>
      DocumentRoot /home/[YourCompName]/localhost2
      #some path of your new host
      ServerName localhost2
      #the name of your new host
      ServerAlias www.localhost2
      #alias of your new host
      </VirtualHost>

  4. Type in your terminal “gedit /etc/hosts” to edit hosts
    • add line :
      127.0.0.1 localhost2
      #127.0.0.1 Your new host name
  5. Restart lampp by execute “/opt/lampp/lampp restart

Now you have two virtual hosts in your computer. You can access it through url http://localhost and http://localhost2. In this case, the two virtual host has its own document root. The default http://localhost has document root in /opt/lampp/htdocs, while the http://localhost2 has document root in /home/[YourCompName]/localhost2.

Have a nice try on Add New Virtual Host XAMPP or LAMPP on Linux

Add New Virtual Host XAMPP or LAMPP on Linux

Add New Virtual Host XAMPP or LAMPP on Linux

Add New Virtual Host XAMPP or LAMPP on Linux

Add New Virtual Host XAMPP or LAMPP on Linux


Feb 15 2012

2nd Generation of My Website

Dear visitor,

Sorry for not submitting new article for a long time.

Currently I am planning to rebuild my website. Currently I am using wordpress for this website. I am still developing the new website. For the next generetaion of my website, I hope it will be more lighter than this one.

I have already made the template and the admin site for my website. And I hope it will be finished in the end of march. I cant focus in developing my website because I have to focus also in my job.

Thanks for your attention. And I hope you will visit my 2nd generation of my website.

Best Regards,

Me


Oct 19 2011

Javascript Delay or Pause or Sleep Loop

Wonder how to make Javascript Delay or Pause or Sleep Loop? In this post, I’ll try to share what i found. This function of Javascript will delay or pause an existing loop for defined time.

Here is the code of Javascript Delay or Pause or Sleep Loop:

function loop(ceil,pause_every,pause_for,count){
	if(!count)count=1;
	if(count 		//execute your code here
		if( (count%pause_every) == 0 && count != 0){
			count++;
			setTimeout("loop("+ceil+","+pause_every+","+pause_for+","+count+");",pause_for*1000);
		}else{
			count++;
			loop(ceil,pause_every,pause_for,count);
		}
	}
}

Call the function like this:

loop(10,3,2);//the code will loop for 10 times and pause for 2 second each 3 times loop.

Hope this Javascript Delay or Pause or Sleep Loop code will be useful for you.

Javascript Delay or Pause or Sleep Loop

Javascript Delay or Pause or Sleep Loop

Javascript Delay or Pause or Sleep Loop

word word
Wonder how to make Javascript Delay or Pause or Sleep Loop? In this post, I’ll try to share what i found. This function of Javascript will delay or pause an existing loop for defined time.

Here is the code of Javascript Delay or Pause or Sleep Loop:

function loop(ceil,pause_every,pause_for,count){
	if(!count)count=1;
	if(count 		//execute your code here
		if( (count%pause_every) == 0 && count != 0){
			count++;
			setTimeout("loop("+ceil+","+pause_every+","+pause_for+","+count+");",pause_for*1000);
		}else{
			count++;
			loop(ceil,pause_every,pause_for,count);
		}
	}
}

hasan Javascript Delay or Pause or Sleep Loop
Javascript Delay or Pause or Sleep Loop
Javascript Delay or Pause or Sleep Loop


Aug 24 2011

My Linkedin

My Linkedin

hasan My LinkedinThis is my linkedin site where you can see my profile more detial. Fell free to connect with me. Please feel free to visit http://id.linkedin.com/in/mhseptiadi

 

 

 


My Linkedin My Linkedin My Linkedin
My Linkedin My Linkedin My Linkedin

My Linkedin

My Linkedin

My Linkedin

word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word


Aug 8 2011

Facebook Login Button with Image

Facebook Login Button with Image

Previously I was searching for how to change the Facebook Login Button with an image. Surfing the internet didn’t gimme answer. I also posting in some coding forum, but there is also no good answer. It cost me more than 2 days when facing this problems. However i found the answer by my self. Therefore in this post i want to share it with you. Because i know facing this problems is tiring.

Before we continue with manipulating the facebook login buton with an image, i asume you already knwo about how to make facebook login button. If you dont know about it yet, please check this. After you read this lets start.

First, Found the fb tag. It should be like:

<fb:login-button></fb:login-button>

Change it into some thing like:

<fb:login-button show-faces="true" width="216">----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</fb:login-button>

In this case, i make the width become 216, because i’ll use an image that have property width=216 and height=72.

The result should be look like:

facebook Facebook Login Button with Image
Facebook

Second, Make your own button. In this case, we will use three div. First for the image, second for the facebook login button, and the last is for the container of both.

First div:

<div style="position:absolute;left:0px;top:0px;width:216px;height:72px;z-index:111;">
<img src="yourimage.jpg" style="cursor:pointer" />
</div>

Second div:

<div style="position:absolute;left:0px;top:0px;width:216px;height:72px;overflow:hidden;z-index:333;opacity:0;filter:alpha(opacity=0);">
<fb:login-button show-faces="true" width="216">----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</fb:login-button>
</div>

The last div will contain both of first div and second div:

<div style="position:relative;width:216px;height:72px;" >
</div>

Third, Combine all of the div. Then the final code will look like:

<div style="position:relative;width:216px;height:72px;" >
<div style="position:absolute;left:0px;top:0px;width:216px;height:72px;z-index:111;">
<img src="yourimage.jpg" style="cursor:pointer" />
</div>
<div style="position:absolute;left:0px;top:0px;width:216px;height:72px;overflow:hidden;z-index:333;opacity:0;filter:alpha(opacity=0);">
<fb:login-button show-faces="true" width="216">----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</fb:login-button>
</div>
</div>

Make sure the width and the height is correct based on your image width and height. Then, copy the final code into your website.

How it works:

The first div that contain your image will be placed under the second div that contain the facebook button. The second div will be exactly overlayed the first div. Then, we make the second div opacity become 0, so it will be invisible. As a result, when you press your image, you actually press the facebook button.


Facebook Login Button with Image Facebook Login Button with Image Facebook Login Button with Image
Facebook Login Button with Image Facebook Login Button with Image Facebook Login Button with Image

hasan Facebook Login Button with Image
word word

Facebook Login Button with Image

Facebook Login Button with Image

Facebook Login Button with Image


Jul 11 2011

Energy Saver in Web Page

Energy Saver in Web Page

Have you imagine if your web page can do some kind energy saver like screen saver in your computer desktop? Do you want to make it happen? Then lets do it togather.

First download required file jquery.js and jquery.idle-timer.js.

Second, Copy the bellow script into your head tag in html file.
<script type="text/javascript" src="[url]/jquery.js"></script>
<script type="text/javascript" src="[url]/jquery.idle-timer.js"></script>

<script type="text/javascript">
(function($){
    var timeout = 10000;//ten second idle. change this var. 1000 means 1 sec.
    $(document).bind("idle.idleTimer", function(){
		position_popup(150,30);
		document.getElementById('popup_area_bg').style.display = 'block';document.getElementById('popup_area').style.display = 'block';
    });
    $(document).bind("active.idleTimer", function(){
		document.getElementById('popup_area_bg').style.display = 'none';document.getElementById('popup_area').style.display = 'none';
    });
    $.idleTimer(timeout);
    $('#timeout').text(timeout/1000);
})(jQuery);

function position_popup(width,height){
height = parseInt(height);
	if(!window.innerWidth){
		if(!document.documentElement.offsetWidth){
			if(!document.body.offsetWidth){
				win_width = 1000;
			}else{
				win_width = document.body.offsetWidth;
			}
		}else{
			win_width = document.documentElement.offsetWidth;
		}
		document.getElementById('popup_area').style.position ='absolute';//need only once
		document.getElementById('popup_area_bg').style.display ='none';//need only once
	}else{
		win_width = window.innerWidth;
	}
	if(!window.innerHeight){
		if(!document.documentElement.offsetHeight){
			if(!document.body.offsetHeight){
				win_height = 1000;
			}else{
				win_height = document.body.offsetHeight;
			}
		}else{
			win_height = document.documentElement.offsetHeight;
		}
		document.getElementById('popup_area').style.top ='100px';
	}else{
		win_height = window.innerHeight;
		inner_top = (win_height - height-25)/2;if(inner_top < 0)inner_top=0;
		document.getElementById('popup_area').style.top = inner_top+'px';
	}
	inner_left = (win_width - width-25)/2;if(inner_left < 0)inner_left=0;
	document.getElementById('popup_area').style.left = inner_left+'px';
	document.getElementById('popup_area').style.width = width;
	document.getElementById('popup_area').style.height = height;
}
</script>

<style type="text/css">
.inner_popup{
	display: none;
	position:fixed;
	text-align:center;
	z-index:1002;
	padding:10px;
	width: 150px;
	height: 30px;
	border: 2px solid;
	border-color:#CCCCCC;
	background-color: white;
	vertical-align:middle;
}
.outer_popup{
	display: none;
	position:fixed ;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: black;
	z-index:1001;
	-moz-opacity: 0.8;
	opacity:.70;
	filter: alpha(opacity=80);
	text-align:center;
}
</style>

Third, copy bellow script into body tag in your html file.

<div id="popup_area_bg">
</div>
<div id="popup_area">
<div style="float:left; width:100%;" align="center">
	Idle Time
</div>
</div>

By implementing energy saver in your web page, I hope, your page can save energy even only in a small amount. The more your page visited by other people, the more you help them to save energy.

Thanks to Paul Irish for jQuery idleTimer plugin so that we can make our Energy Saver in Web Page.

Refference: http://paulirish.com/2009/jquery-idletimer-plugin/


Energy Saver in Web Page Energy Saver in Web Page Energy Saver in Web Page
Energy Saver in Web Page Energy Saver in Web Page Energy Saver in Web Page

hasan Energy Saver in Web Page
word word

Energy Saver in Web Page

Energy Saver in Web Page

Energy Saver in Web Page


Jun 24 2011

Handle Old Open PHP Tag

Handle Old Open PHP Tag

Continuing my previous post PHP Auto Replace Multiple Files Content, you can esily make the old php open tag <? to be handled by new php.

You have to change your php.ini file. In php.ini file, found a row with “short_open_tag = Off” then change it with “short_open_tag = On“. After that restart your apache server.


Handle Old Open PHP Tag

hasan Handle Old Open PHP Tag
word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word

Handle Old Open PHP Tag

 Handle Old Open PHP Tag

Handle Old Open PHP Tag

Handle Old Open PHP Tag


Jun 22 2011

PHP Auto Replace Multiple Files Content

PHP Auto Replace Multiple Files Content

Previously my best friend told me about his problems in php. He has a bunch of php file that already outdated.These files use php 4 format. He requested me if there is a way to change the format <? used in those files into <?php that used in current php format. Therefore, I made a php script to do such thing.

This script has feature:

  • List all files in current folder except the script it self
  • Read each file one by one
  • Replace requested string
  • Save it
This is the script:
<?php
//if file is too many, there is a possibility that the script exceed the max exection time
$this_file = 'index.php';//this is the script file for exception
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";

			if($file != $this_file){

				$handle2 = fopen("$file", "rb");
				$contents = '';
				while (!feof($handle2)) {
				  $contents .= fread($handle2, 8192);
				}
				$contents = str_replace("<?", "<?php", $contents);// for replacing <? into <?php
				//for replacing deprecated function, you need regex
				echo htmlspecialchars($contents).'<hr><br>';
				fclose($handle2);

				$fp = fopen("$file", 'w');
				fwrite($fp, $contents);
				fclose($fp);
			}
        }
    }
    closedir($handle);
}
?>

Just copy the script into a folder where resides the files that you want to replace the content.



PHP Auto Replace Multiple Files Content PHP Auto Replace Multiple Files Content PHP Auto Replace Multiple Files Content
PHP Auto Replace Multiple Files Content PHP Auto Replace Multiple Files Content PHP Auto Replace Multiple Files Content

hasan PHP Auto Replace Multiple Files Content
word word

PHP Auto Replace Multiple Files Content

PHP Auto Replace Multiple Files Content

PHP Auto Replace Multiple Files Content