Thursday, December 31, 2015

Saturday, December 26, 2015

postgresql - how to install under ubuntu (debian)

uBuntu Community Wiki - PostgreSQL

How To Install and Use PostgreSQL on Ubuntu 14.04 @ Digital Ocean

install via apt-get

$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib

login as linux user postgres (that was auto-created during installation)

$ sudo -i -u postgres 

launch interactive postgresql console

$ psql

quit interactive console

$ \q

djfhjdhfjdhjfhdf

Monday, December 7, 2015

David Schachter - Python Optimization Case Study


David Schachter is a data analytics heavy-weight (check out his resume @ LinkedIn), and offers up some candid advice in this entertaining case study in performance optimization of a data-focused python application.





Original talk/con sponsored by Marakana Open Source Learning.

Tuesday, November 10, 2015

SQL Server - Strip NameSpace from XML String

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION Strip_XML_NS
(
    @xml varchar(max)
)
RETURNS varchar(max)
AS
BEGIN
    DECLARE @stripped varchar(max)

    declare @i int
    set @i = CHARINDEX('"', @xml) - LEN('xmlns="')

    declare @f int
    set @f = CHARINDEX('"', @xml, CHARINDEX('"', @xml) + 1) + 1

    declare @ns varchar(max)
    set @ns = SUBSTRING(@xml, @i, @f - @i)

    set @stripped = REPLACE(@xml, @ns, '')
   
    RETURN @stripped
END
GO

Tuesday, October 20, 2015

MS SQL Server - Select Columns Names with System Type for User Table

declare @tableName varchar(max)
set @tableName = 'Products'

select so.name as TableName, sc.name as ColumnName, st.name as SystemType
from sys.columns sc
inner join sys.objects so on (sc.object_id = so.object_id)
inner join sys.types st on (sc.system_type_id = st.system_type_id)
where
    (so.type_desc = 'USER_TABLE')
    and
    (so.name = @tableName)

Wednesday, August 26, 2015

vsftpd linux ftp server daemon

$ sudo apt-get install vsftpd

config @ /etc/vsftpd.conf

$ sudo service vsftp start

$ sudo service vsftp stop

Saturday, August 15, 2015

ubuntu linux trash location

~/.local/share/Trash/files$

Saturday, August 8, 2015

Friday, August 7, 2015

python -m SimpleHTTPServer

to serve up the current folder via HTTP server

    $ python -m SimpleHTTPServer

Wednesday, August 5, 2015

Sunday, August 2, 2015

python docstring conventions - PEP 0257


PEP 0257 - Docstring Conventions:

>>>

One-line Docstrings

One-liners are for really obvious cases. They should really fit on one line. For example: 

def kos_root():
    """Return the pathname of the KOS root directory."""
    global _kos_root
    if _kos_root: return _kos_root
    ...
Notes:
  • Triple quotes are used even though the string fits on one line. This makes it easy to later expand it.
  • The closing quotes are on the same line as the opening quotes. This looks better for one-liners.
  • There's no blank line either before or after the docstring.
  • The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ...".
  • The one-line docstring should NOT be a "signature" reiterating the function/method parameters (which can be obtained by introspection). 

    Don't do: 

    def function(a, b):
        """function(a, b) -> list"""
     
    This type of docstring is only appropriate for C functions (such as built-ins), where introspection is not possible. However, the nature of the return value cannot be determined by introspection, so it should be mentioned. The preferred form for such a docstring would be something like: 

    def function(a, b):
        """Do X and return a list."""
     
    (Of course "Do X" should be replaced by a useful description!)

Multi-line Docstrings

Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. The summary line may be used by automatic indexing tools; it is important that it fits on one line and is separated from the rest of the docstring by a blank line. The summary line may be on the same line as the opening quotes or on the next line. The entire docstring is indented the same as the quotes at its first line (see example below). 

Insert a blank line after all docstrings (one-line or multi-line) that document a class -- generally speaking, the class's methods are separated from each other by a single blank line, and the docstring needs to be offset from the first method by a blank line.

The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the script is invoked with incorrect or missing arguments (or perhaps with a "-h" option, for "help"). Such a docstring should document the script's function and command line syntax, environment variables, and files. Usage messages can be fairly elaborate (several screens full) and should be sufficient for a new user to use the command properly, as well as a complete quick reference to all options and arguments for the sophisticated user. 

The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each. (These summaries generally give less detail than the summary line in the object's docstring.) The docstring for a package (i.e., the docstring of the package's __init__.py module) should also list the modules and subpackages exported by the package. 

The docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects, exceptions raised, and restrictions on when it can be called (all if applicable). Optional arguments should be indicated. It should be documented whether keyword arguments are part of the interface. 

The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its __init__ method. Individual methods should be documented by their own docstring. 

If a class subclasses another class and its behavior is mostly inherited from that class, its docstring should mention this and summarize the differences. Use the verb "override" to indicate that a subclass method replaces a superclass method and does not call the superclass method; use the verb "extend" to indicate that a subclass method calls the superclass method (in addition to its own behavior). 

Do not use the Emacs convention of mentioning the arguments of functions or methods in upper case in running text. Python is case sensitive and the argument names can be used for keyword arguments, so the docstring should document the correct argument names. It is best to list each argument on a separate line. 

For example:

def complex(real=0.0, imag=0.0):
    """Form a complex number.

    Keyword arguments:
    real -- the real part (default 0.0)
    imag -- the imaginary part (default 0.0)
    """
    if imag == 0.0 and real == 0.0:
        return complex_zero
    ...
 
Unless the entire docstring fits on a line, place the closing quotes on a line by themselves. This way, Emacs' fill-paragraph command can be used on it
<<<
 

Friday, July 31, 2015

python wifi


wifi by rockymeza

documentation @ readthedocs.org
project @ github

$ sudo apt-get install python3-pip
$ sudo pip3 install wifi


Tuesday, July 28, 2015

Messaging with Python & RabbitMQ

Considering using RabbitMQ to implement multi-process messaging and work-flow co-ordination, the RabbitMQ messaging system is well reviewed by Christian Bick @ bitsuppliers.com.

The bit that concerns me is this: [bold emphasis mine]

>>>
Protocol

RabbitMQ is based on AMQP, an open protocol which aims to become a standard used by all messaging middle ware. In theory that means you can exchange two brokers supporting the same AMQP version without having to make adoptions to clients which prevents vendor lock. Also, it shall enable brokers of different vendors to interoperate with each other which enables wide usage across company borders.

So much to theory, the real world looks quite different. From earlier versions of AMQP to version 0-9-1 RabbitMQ almost completely implemented AMQP. As AMQP used to be a protocol in development untill 2011, naturally many protocol versions followed each other within short time periods. RabbitMQ was one of few brokers that rapidly adopted new versions and as such interoperability and exchangeability suffered from these rapid version changes. Still, there was the hope that this would change as soon as the protocol being published in its first final version.

AMQP 1.0 was announced in 2011 and the drafts were a big surprise. Instead of fixing the standard that evaluated over years, version 1.0 was a real change of paradigms. Now, there are no plans at RabbitMQ to implement version 1.0 as the guys there don’t regard AMQP 1.0 as a successor of AMQP 0-9-1. But to implement a version of a standard which is only seriously supported by RabbitMQ is meaningless.

<<<

Sunday, July 26, 2015

debian / ubuntu sticky notes

props to Ji M:

$ sudo add-apt-repository ppa:umang/indicator-stickynotes

$ sudo apt-get update

$ sudo apt-get install indicator-stickynotes

Monday, May 4, 2015

GPS Calculation Methods

What Method Does Garmin Use to Calculate Distance ?

Edward Sargisson, at Trail Hunger, concludes that Garmin devices do not use the 3d slope distance when reporting distances, but rather the distance at sea level.

Calculation of the Distance Between 2 Points on the Surface of a Great Sphere - the Haversine Formula

This can be achieved using the Haversine Formula, here is a javascript implementation from Movable Type Ltd:

var Bx = Math.cos(φ2) * Math.cos(λ2-λ1);
var By = Math.cos(φ2) * Math.sin(λ2-λ1);
var φ3 = Math.atan2(Math.sin(φ1) + Math.sin(φ2), Math.sqrt( (Math.cos(φ1)+Bx)*(Math.cos(φ1)+Bx) + By*By ) );
var λ3 = λ1 + Math.atan2(By, Math.cos(φ1) + Bx);

See Also

R. W. Sinnott, "Virtues of the Haversine".  Sky and Telescope, vol 68, no 2, 1984

Sunday, May 3, 2015

Practical Object Orientation in JavaScript

http://www.phpied.com/3-ways-to-define-a-javascript-class/

methods defined internally

function Apple (type) {
    this.type = type;
    this.color = "red";
    this.getInfo = function() {
        return this.color + ' ' + this.type + ' apple';
    };
}

methods added to the prototype

function Apple (type) {
    this.type = type;
    this.color = "red";
}
 
Apple.prototype.getInfo = function() {
    return this.color + ' ' + this.type + ' apple';
};

using object literal syntax to create a singleton class

var apple = {
    type: "macintosh",
    color: "red",
    getInfo: function () {
        return this.color + ' ' + this.type + ' apple';
    }
}

Saturday, April 25, 2015

Convert .MP4 to .AVI - Linux

$ sudo apt-get install mencoder

$ mencoder source_movie.mp4 -channels 6 -ovc xvid -xvidencopts fixed_quant=4 -vf harddup -oac pcm -o dest_movie.avi

Wednesday, April 8, 2015

simple python http server - BaseHTTPServer vs apache

http://stackoverflow.com/questions/5693741/whats-difference-between-a-simple-webserver-and-apache-server

Question

What's difference between a simple webserver and Apache server?

Answer @ ninjagecko
Or in other words, if i want to use python to implement a server which can be put into use of business, what also should i do?
There are already python-based web servers, such as CherryPy (which I think is intended to be a web server solution on the same stack level as Apache; it is more python-based though, and Apache has been around a lot longer).

If you wish to write a lightweight extremely simple webserver from scratch, there is probably nothing wrong with using BaseHTTPServer, other than perhaps a few outstanding design issues (I hear race conditions might permanently clog a socket until a thread dies).

Though I would not recommend it (alone) for business, some of the big boys use BaseHTTPServer with a bit of extra machinery: http://www.cherrypy.org/browser/trunk/cherrypy/_cphttpserver.py?rev=583

To elaborate, Apache is the industry standard. It has a plethora of configuration options, a security team, vulnerability mailing lists I think, etc. It supports modules (e.g. mod_python). Python-based web servers also support python-based modules (maybe they might allow you access to non-python things) via something called a WSGI stack; a WSGI application can run on any python-based web server (and Apache too, which also has a modwsgi); I think they are narrower in scope than Apache modules.

Apache module examples: http://httpd.apache.org/docs/2.0/mod/
WSGI examples (not a valid comparison): http://wsgi.org/wsgi/Middleware_and_Utilities

I might code my own webserver if I'm doing something extremely lightweight, or if I needed massive control over webserver internals that the module interfaces could not provide, or if I was doing a personal project. I would not code my own server for a business unless I had significant experience with how real-world web servers worked. This is especially important from a security vulnerability point-of-view.

For example, I once wrote a web-based music player. I used a BaseHTTPServer to serve music out of a sandbox I had written to ensure that people couldn't access arbitrary files. Threading was a nightmare. (I recall a bug where you needed to pass special arguments to Popen since threading caused an implicit fork which would cause hangs on dangling file descriptors.) There were other various issues. The code needed to be refactored a lot. It can be very worthwhile for a personal project, but is a significant undertaking and not worth it for a business that just needs a website.

I know two startups who have been content using Pylons (using Paste) or Turbogears (using CherryPy) in the past, if you're looking for a lightweight python web server stack. Their default template systems are lacking though. The choice between Apache and a leaner more python-based web server may also depend on the skillset of your co-developers.

Friday, March 13, 2015

uBuntu - Error Reporting - Turn Off

edit /etc/default/apport, e.g. 

$ sudo gedit /etc/default/apport
 
then set 'enabled' to 0, and save 

Tuesday, March 10, 2015

Dieter Ram's 10 Principles of Design

Dieter Rams is an industrial designer, renowned for the functional, minimal style he demonstrated at Braun, where he worked from 1965 to 1995.

He is cited as a major influence on designer Johnathan Ive, who is associated with the functional, minimalist design aesthetic reintroduced to Apple products with the advent of the ipod music player, and continued in their phone and operating system product lines.

- - -

Good design:

    Is innovative - The possibilities for progression are not, by any means, exhausted. Technological development is always offering new opportunities for original designs. But imaginative design always develops in tandem with improving technology, and can never be an end in itself.

    Makes a product useful - A product is bought to be used. It has to satisfy not only functional, but also psychological and aesthetic criteria. Good design emphasizes the usefulness of a product whilst disregarding anything that could detract from it.

    Is aesthetic - The aesthetic quality of a product is integral to its usefulness because products are used every day and have an effect on people and their well-being. Only well-executed objects can be beautiful.

    Makes a product understandable - It clarifies the product’s structure. Better still, it can make the product clearly express its function by making use of the user's intuition. At best, it is self-explanatory.

    Is unobtrusive - Products fulfilling a purpose are like tools. They are neither decorative objects nor works of art. Their design should therefore be both neutral and restrained, to leave room for the user's self-expression.

    Is honest - It does not make a product appear more innovative, powerful or valuable than it really is. It does not attempt to manipulate the consumer with promises that cannot be kept.

    Is long-lasting - It avoids being fashionable and therefore never appears antiquated. Unlike fashionable design, it lasts many years – even in today's throwaway society.

    Is thorough down to the last detail - Nothing must be arbitrary or left to chance. Care and accuracy in the design process show respect towards the consumer.

    Is environmentally friendly - Design makes an important contribution to the preservation of the environment. It conserves resources and minimizes physical and visual pollution throughout the lifecycle of the product.

    Is as little design as possible - Less, but better – because it concentrates on the essential aspects, and the products are not burdened with non-essentials. Back to purity, back to simplicity.

Sunday, February 8, 2015

GIT Sub-Modules

use other git modules within your repo by reference


git-scm.com/book documentation

Monday, February 2, 2015

Dump Dates to CSV File - C#

#region Dump Output Dates to File

string filePath = "c:/dev/projected_dates.csv";

string actualDatesCSV = string.Join(",",
 actualDates
 .OrderBy(x => x)
 .Select(x => x.ToShortDateString())
 );

using (var sw = new System.IO.StreamWriter(filePath))
{
 sw.Write(actualDatesCSV.Replace(",", "\n"));
}

#endregion

Thursday, January 15, 2015

Drop Tables Script for Non Inter-Dependant Tables

use [target_database]

select 'drop table [' + name + ']'

from sys.objects

where type = 'U'

OR

EXEC SP_MSFOREACHTABLE 'drop table ?'