Python styles guide (PEP 8) in Pdf and Docx

There is no doubt that following general conventions is “must have” for developers for any developers. I like read most of documentation for PLs on iPad and sometimes without internet connection. I could not find any good pdf version of styles for Python to read on tablet offline and so I decided to make it by myself. Now I am going to share with you *.docs and *.pdf doc versions I created.
The original document you can find here: http://legacy.python.org/dev/peps/pep-0008/

    

Amazon Elastic Beanstalk: add/change php.ini settings

Hi folks,

I’m going to tell you how to add (or change/rewrite) settings for php.ini if you deploy your project on elastic beanstalk. I need to change two values in php.ini upload_max_filesize and post_max_size.

To start with, need add directory with name `.ebextensions` and add file there with some meaningful name with trailing `.config`. I created `phpini.config` file

Continue reading “Amazon Elastic Beanstalk: add/change php.ini settings” »

Switch off MySQL autostart on Mac OS

My operation system is Mac OS 10.6 and I’ve installed MySQL sometime ago. I need the database but I don’t like when it works all the time.

So, to turn off autostart for MySQL need:
#1 Open file /etc/hostconfig with sudo privileges, for example with vi editor
#2 Chnage line from “MYSQLCOM=-YES-” to “MYSQLCOM=-NO-”

The location of original script that launch the DB server at startup is /Library/StartupItems
But this is only for your information no need to change something there.

Cookie in Javascript

Http protocol is stateless, so there is no native way to save some information between pages. But fortunately we have cookie in browsers.

First of all, how to check if browser supports cookie:

var isCookieEnabled = navigator.cookieEnabled;
alert(isCookieEnabled ? 'Cookie Enabled' : 'Cookie Disabled')

And when you checked that cookie works need to use the cookie storage. The easiest way is to use jQuery plugin for this Read how to use jQuery Cookie plugin

Javascript’s foreach

Javascript doesn’t have foreach statement, but it’s simple to emulate one:

<script type="text/javascript">
var arr = ['one', 'two', 'three', 'four', 'five', 'etc'];
for (var i in arr) {
	var element = arr[i];
	alert(i + ': ' + element);
}
</script>

It’s actually equivalent of foreach in other languages like PHP.
If you have jQuery on your webpage you can use jQuery’s foreach:

<script type="text/javascript">
var arr = ['one', 'two', 'three', 'four', 'five', 'etc'];
jQuery.each(arr, function(index, element) {
	alert(index + ': ' + element);
});
</script>

Hello world on Javascript (Browser)

“Hello world” is actually very simple program on every programming language and it’s just writting to out stream or document or whatever simple two-words sentence – “Hello world”.
There are several ways to write hello world script for browser.

Optioin #1: Write in document:

<script type="text/javascript">
document.write("Hello World!");
</script>

Option #2: Shop standard browser message:

<script type="text/javascript">
alert("Hello World!");
</script>

Optioin #3: Write in browser’s title:

<script type="text/javascript">
document.title = "Hello World!";
</script>

is_array() function for Javascript

To check whether variable array or not need to use type check syntax: instanceof:

[] instanceof Array // true
'string' instanceof Array // false

You can make a function to incapsulate the feature:

function is_array(variable) {
	return variable instanceof Array
}

Using:

is_array([]) // true
is_array('string') // false

jQuery also has the similar function:

$.isArray([]) // true
$.isArray('string')