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).

How to run application on specified interface?

If you have two interfaces, you can run programs using one of them (despite the fact that Windows selects default interface based on a metric value). For example I virtualize Windows 7 and I need same static ip for it that my host computer uses. It’s OK, in this scenario I can run applications using Virtualbox NAT (this virtual adapter ip is something like 10.0.2.15). But I’m also a Heroes III gamer and I love to play with my coleagues using LAN. So there is need for a second adapter in bridged mode (with ip like 192.168.x.x).

What can I do?
Amazingly there is a Windows application that can do that. Simply download ForceBindIP from this site.

Usage is simple as that:

ForceBindIp -i 10.0.2.15 c:\Windows\System32\mstsc.exe

10.0.2.15 – interface ip

Remember to pass full path for a program that you’re trying to run!

How to delete file permanently in Linux?

Most of Linux distributions have shred already installed. So it’s really easy to delete a file in a secure manner:

shred -u -z -n 26 topsecret.txt

Meaning of used switches:

-n [N]Overwrite a file N times. For example, -n 20 will perform twenty passes over the file’s contents.
-uRemove the file after you’ve shredded it. You’ll probably want to use this option in most cases.
-zAfter shredding a file with random bits (ones and zeros), overwrite the file with only zeros. This is used to try and hide the fact that the file was shredded.

There is a Windows gui alternative available at http://www.fileshredder.org/.