Wednesday, April 30, 2014

Before you buy Cloud Mining

Why would a company sell already bought hashing power to someone else without making 100% bitcoin profit mining it alone. It doesn't make sense at all unless the seller is trying to sell it for a highly over priced amount or scam you.

Some companies say that you can trade the bought GHS but even then bitcoin difficulty rises and GHS drops in value very fast. Unless you are a good short term trader GHS trading is a ripoff. This apply to mining as well with increasing difficulty you will get lesser returns for your GHS plus increased maintenance fee.

Just my thoughts, Please do proper research before you invest in cloud mining.

Tuesday, March 4, 2014

Mahara web services - simple guide

Mahara web services can be installed as a plugin. Installation is a easy process. you can find the steps in here https://wiki.mahara.org/index.php/Plugins/Auth/WebServices#Installation_Instructions

extract the zip file and put to folders inside mahara /path/to/mahara/webservice and /path/to/mahara/auth/webservice

login to mahara as admin goto menu extensions -> Plugin administration under Plugin type: auth heading install webservice

code check for https so if you do not have SSL in your site and you want to test the web services you can comment out https check part in the code (NOT recommended for a production server)

for example if you want to use REST go to the folder webservice -> rest inside server.php comment

// you must use HTTPS as token based auth is a hazzard without it
/*if (!is_https()) {
    header("HTTP/1.0 403 Forbidden - HTTPS must be used");
    die;
}*/

Now you can test web services using the built in Web service test client
click Configuration link near webservice plugin. Enable WebServices master switch. under Manage Service Access Tokens add a user and generate a token. Now click Web service test client tab and select
protocol - REST
Authentication Type - Token
Service - choose the service you selected when generating token.
Select a function and enter token.

You can also use curl from another site to access the webservice like this

<?php
$service_url = 'http://yoursite.com/mahara/webservice/rest/server.php';
$token = 'your token';

$curl = curl_init($service_url);

$curl_post_data = array(       

 'wsfunction' => 'mahara_user_get_users', // the function to be called
      'wstoken' => $token //token need to be passed in the url
);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);

$info = curl_getinfo($curl);

if ($curl_response === false) {
    $info = curl_getinfo($curl);
    curl_close($curl);
    die('error occured during curl exec. Additioanl info: '.var_export($info));
}
curl_close($curl);

header("Content-type: text/xml");

echo $curl_response;

?>

Sunday, March 2, 2014

Mahara - Sorry, your registration attempt was unsuccessful. This is our fault, not yours. Please try again later.

Fix is to setup email setting in site options. I installed Mahara on a shared hosting. I'm not sure how to setup email setting required for localhost other than giving working SMTP details. Administration -> Site options -> Email settings

Thursday, February 13, 2014

div losing background color/image when resizing the browser window

When you have div width 100% it apply to browser viewpoint only not the max page width. This can be a problem when you have another div with a fixed width length. The fix is to put a min-width with max possible page width.



<html>
<head>
<style>
html, body{margin:0; padding:0;border: 0;outline: 0;}
</style>
</head>
<body>

<!--The problem-->
<div style="margin:0; width:100%; background-color:#060;">
 Header 1
</div>

<div style="margin:0 auto; width:1000px; background-color:#03C;">     
 Text Line 1
</div>

<br /><br />

<!--Fix-->
<div style="margin:0; width:100%; min-width:1000px; background-color:#060;">
 Header 2
</div>

<div style="margin:0 auto; width:1000px; background-color:#03C;">     
 Text Line 2
</div>

</body>
</html>

Don't forget padding widths when calculating min width.

Wednesday, February 12, 2014

Cannot login to Games for Windows LIVE

Login issue for me was caused by two-step verification. you can either disable it temporally till you finish game or you can use a App password that you can find in your Live account under "Security info".

GFWL can be very annoying at times. I had problems with it every time it was required to play a specific game. Wish they at least give a detailed error message without wasting my time for hours looking for fixes.

Thursday, February 6, 2014

HD 7750 cypto coin mining experience

HD 7750 is a entry level card for mining any kind of coin. suitable for casual mining while you do other stuff in the pc. I mine Feathercoin (FTC) as it has a very low difficulty but I think Litecoin will give the same return when converted to Bitcoins. I get around 2.5FTC per day with wemineftc.com pool.

My HD 7750 punch 134 khash/s on Intensity level of 13 in GUIminer-scrypt
GPU clock increased to 825MHz (core speed 800)
Memory clock speed decreased to 700Mhz to reduce temperature. you can change card settings using amd catalyst control center.



It can easily go over 150 Khash/s with more GPU overclocking and increasing the intensity level. I haven't tried to push the card that far since increase core speed make temperature go over the roof.

How to get all results without the first row from a MySQL table

To exclude first row you have to use MySQL limit clause.

select * from table limit 1, 10000000

You can pass 2 values to limit clause first one is the starting row. Row index start with 0 so you have to put 1 to remove first row. Second parameter is the number of result u need to retrieve. Put a number that is larger than max rows of table.

Sunday, September 15, 2013

Disable other_vhosts_access.log in ubuntu

Check the following location for apache2.conf and other-vhost-access-log
/etc/apache2/apache2.conf
/etc/apache2/conf.d/other-vhost-access-log

Open those files and check for the line with other_vhosts_access.log and comment them out with # sign in front of the line.

Restart Apache.

Monday, April 1, 2013

Fixing MP4 not playing until full video loads in browser

I had a problem where my mp4 videos were not played by video.js player until the video was fully downloaded by the browser. after some searching I found out it was because mp4 file metadata ( moov atom) is on the end of the file and the player cannot locate it for streaming when initially played.

I was saved by this small php library http://code.google.com/p/moovrelocator/
This will read a video and move MOOV-Atom to the front of the mp4 file.

there is a demo in _demo folder. if you get errors finding the paths, try giving direct paths like this in index.php

$inFile = '../../videos/'.$tempv;
// output (processed file)
$outFile = '../../new_videos/'.$tempv;

if you get zend errors try giving direct paths in Moovrelocator.class.php


// atom poc class
require_once 'atom/Atom.class.php';

// bytearray to operate direct on bytes in memory just to simulate Adobe's AS3 Bytearray
require_once 'bytes/Bytearray.class.php';

// transform (taken from php-reader)
require_once 'bytes/Transform.class.php';

you may also want to change your php.ini max execute time and memory use if you are looping through lot of videos in a folder.

Sunday, October 28, 2012

php file upload error messages in a php array

Hope this will be useful to someone, all the php file upload error codes and messages in an array.

<?php

$error_codes = array(
        0=>"There is no error, the file uploaded with success",
        1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
        2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
        3=>"The uploaded file was only partially uploaded",
        4=>"No file was uploaded",
        6=>"Missing a temporary folder",
        7=>"Failed to write file to disk",
        8=>"A PHP extension stopped the file upload"
);

/* Posssible Usage */

if($_FILES["userfile"]["error"] > 0){
   
  $code = $_FILES["userfile"]["error"];
  echo $error_codes[$code];
}
else{
 
 //do the processing
}
 
?>

Tuesday, October 23, 2012

How to change default timezone in Ubuntu command-line

In a Ubuntu / Debian based Linux system you can use the following command to run the timezone setup to change the default timezone
dpkg-reconfigure tzdata

Monday, October 22, 2012

High Swapping On Linode 512 - KeepAliveTimeout

I thought of sharing my experience on handling the high swapping issue I faced recently. There is nothing wrong with Linode service, its just my dumb Apache configurations.

Linode is a great hosting service but for a Linux administration newbie it can be a challenging place.

Swapping problem was a nightmare, I tried adding another 512MB to the Linode box and still it goes into full swap. Then I get to know about the Apache KeepAliveTimeout.

KeepAliveTimeout - Amount of time the server will wait for subsequent requests on a persistent connection.

Unfortunately for me the default value was 15 which is a super high value. After changing the value to 4 all was smooth again.

Swapping can occur for many reasons like bad scripting but KeepAliveTimeout value can be a main suspect :)

Tuesday, October 16, 2012

How to check and fix Domain Canonicalization (www)

It's a common configuration in web servers to point both urls of www.example.com and example.com to same content. This is a bad practice in terms of SEO because they regarded as duplicate content. If you have access to the .htaccess and assuming your Apache server has mod_rewrite enabled, you can add following lines to redirect traffic and issue a 301 (Moved Permanently).
I prefer my site addresses without www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

If you like to have your addresses with www use the following
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

If you have any sub domains like blog.example.com do not use the above code.

Tuesday, August 7, 2012

How to find MPM mode of Apache - Prefork or Worker

to find the Apache MPM mode you can simply run following command.

in Ubuntu u can try
apache2 -V

in CentOS type of linux u can try
httpd -V

Thursday, February 10, 2011

How to fix gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file

Sometimes php will through a error when using the imagecreatefromjpeg() for some jpge images saved by cameras and photo editing softwares. When I search the internet for a solution I found this great article which fix the problem http://worcesterwideweb.com/2008/03/17/php-5-and-imagecreatefromjpeg-recoverable-error-premature-end-of-jpeg-file/

Thursday, January 13, 2011

How to loop A-Z in php

Just like counting numbers :)

$letter = "A";
for($i = 1; $i<= 26; $i++)
{
  $letter++;
  echo $letter;
}

Saturday, September 25, 2010

Cannot make the website html validate? try HTML Tidy

Sometimes you cannot seems to find the line where the validation errors come from. In such cases you can try using HTML Tidy to do a auto clean up.



W3C Markup Validation Service also has this option. or you an check out the project page.

http://tidy.sourceforge.net/

Tuesday, September 7, 2010

Magento Video Tutorials: Thanks Armando Roggio :)

Cannot express how greatful I am to this guy. http://www.ecommercedeveloper.com/articles/1540-Building-a-Magento-Theme-Start-to-Finish-Part-One-Prolegomena

I tried to start Magento several times and just got frustrated with the issues with locahost and complex nature of the file structure.
but thanks to above tutorial Magento is like riding a bike.

Videos are on version 1.3 but after reading this note about version 1.4 you can follow the tutorials easily on 1.4

Magento's Theme Hierarchy--Changes in CEv1.4 and EEv1.8

Thursday, September 2, 2010

Mangento Sample Data - 404 Page Error

I see few solutions for this error in the web but for me following steps corrected my error.
Magento Version - 1.4.1.1

Admin -> System -> Index Management -> Reindex all given Indexes

Sri Lanka District and City List Sql File

For a recent project I had to find all the Sri Lankan District and related Cities to populate in two drop downs. The list is not fully complete and Kilinochchi District is not in the list.
Districts - 24
Cities - 2044

Two tables, city table refer district table by did.

Download Sri Lankan District - City Sql file

You can easily import this sql file to mysql using phpmyadmin.