PHP reading problem with files larger than 2 GB

If you’ll ever have problem with opening (fopen) and reading (fread) files larger than 2 GB in your PHP script. Check your version of scripting engine. In my case switching to 64 bit solved the problem. Please mind that this error is very hard to debug because PHP does not log anything (same as MS IIS) in such case. It simply resets client connection…

How to list all PostgreSQL databases and their sizes in MB

You must provide proper database name and user:


File: gistfile1.txt
-------------------

psql -c "SELECT pg_database.datname, pg_database_size(pg_database.datname), pg_size_pretty(pg_database_size(pg_database.datname)) FROM pg_database ORDER BY pg_database_size DESC;" -d  

How to find Raspberry Pi using MAC address

When you want to find your headless but networked Raspberry Pi and you’re lazy like me use nmap:

sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'

Mask /24 means that addresses from 192.168.1.0 to 192.168.1.254 will be searched. You can extend that to /16 if you don’t know subnet of your device.

How to obscure your WordPress version and troll the attacker a little…

One of my company’s WordPress installations has been hacked by Turkish hackers recently. After quick investigation I’ve found that script version was little bit old (not a very popular website, mea culpa, not updated very often). In case you didn’t know, WordPress is bundled with readme file by default. I’ve found that malicious scripts or people use that to determine your version’s branch. So I’ve decided to Troll them a little bit… Continue reading How to obscure your WordPress version and troll the attacker a little…

How to add Bower component when it’s not in the repository?

Sometimes component that you want to use in your project isn’t available in Bower repo. There is a way to install it, even in very specified version. Go to project’s Github, in my case it’s here. Copy URL from the browser, and paste it somewhere. Now go to relases and click commit id that you’re interested in (this random blue colored string):

After that you’ll see full commit id, in this case it’s fef978b279c546923ad4f4118acea4d503e7596c. Paste that to the end of repository URL you’ve copied earlier. Remember to prefix it with # char and add .git to the URL:

https://github.com/bfintal/Counter-Up.git#fef978b279c546923ad4f4118acea4d503e7596c

Finally mix it with your bower.json file. Here’s full example:

{
	"name": "Realhero report",
	"description": "Report template based on New Age",
	"main": "index.js",
	"authors": ["Konrad Fedorczyk"],
	"license": "ISC",
	"homepage": "http://realhe.ro",
	"private": true,
	"ignore": ["**/.*", "node_modules", "bower_components", "test", "tests"],
	"dependencies": {
	    "bootstrap": "^3.3.7",
	    "font-awesome": "^4.6.3",
   	 	"jquery": "^1.11.3",
   	 	"simple-line-icons": "^2.3.2",
   	 	"morris.js": "^0.5.1",
   	 	"jqvmap-fedek6": "https://github.com/fedek6/jqvmap.git#774c12a57916ab82e17406203bb41522dfe0e38b",
   	 	"Counter-Up": "https://github.com/bfintal/Counter-Up.git#fef978b279c546923ad4f4118acea4d503e7596c"
	}
}

Look at the last line of dependencies part, here’s component that I’ve added.

How to programmatically select option in a HTML list using jQuery?

This is very simple solution to select specified option in a HTML select list.

You just need to use the val function on a select element to set it’s value. It’s simple like that:

$('select#identificator').val('value of existing option value');

Check working example on the JSFiddle: http://jsfiddle.net/fedek6/B3Ehj/

How to check visibility state in jQuery toggle function?

Here is a quick tip how to check visibility state of a toggled element in jQuery:

$('#element').toggle('slow', function() {
  if($(this).is(':hidden')) {
    $(this).text('This element is hidden.');
  }
  else {
    $(this).text('This element is visible.');
  }
});

Force Yii to republish assets every page refresh

During webapp development you’ll need often assets republication. When you publish assets using directory path, framework won’t republish them automaticaly. So what can you do? It’s plain simple. Use YII_DEBUG constant as fourth argument in publish function.

$assetPath = Yii::app()->assetManager->publish(Yii::getPathOfAlias('application.modules.components.assets'), false, 1, YII_DEBUG);

From this moment Yii will republish assets on every page refresh only in debug mode (it won’t consume your resources in production mode).