- angular.config only accepts providers
- Every service and factory are the instances of the providers
e.g.
angular.module('myApp') .service('FooService', function(){ //...etc }) .config(function(FooServiceProvider){ //...etc });Reference: http://stackoverflow.com/questions/17485900/injecting-dependencies-in-config-modules-angularjs
2015年1月14日 星期三
[AngularJS] Basic Concepts
Here are the basic concepts of Angularjs, these concepts are barely well documented by the officials.
2014年12月27日 星期六
[Django] Human readable text in admin panel
In Django, when we are dealing with the admin panel, we can specify human readable text for the column through different methods
- Make it when building the corresponding model
e.g.1: question_text = models.CharField('question', max_length=200)
e.g.2: pub_date = models.DateTimeField('date published') - Or, you can make it through the admin.py, Django's build-in admin model
short_description
e.g.: was_published_recently.short_description = 'Published recently?' - Or you let Django do the rest of the job using class option 'list_display'
list_display = ('first_name', 'last_name')
Django will set column name as First name and Last name where they are both 'database fields', underscores will be evaluated as spaces
Django makes the first parameter as the field show in admin UI, in this case "Date published" and "Question" will be shown.
The corresponding column will be shown with readable text
[Python] Basic data types
There are several data structures in Python, the following are some key notes for reference
- List
- Example: a=[1, 2, 3, 4, 5]
- Mutable (support modification of objects like a.append(6)
- Support stack operations like "pop", "append"
- looping (1 expression only) squares = [x**2 for x in range(10)]
- looping using traditional for
for x in [1,2,3]:
x = x**2 - Tuple
- Example: tup = (1, 2, 3, 'wahaha') (Always enclosed with parentheses!)
- Immutable -> tup[0] = 100 -> Not allowed!!
- Can contain lists
tup = (['a', 'b'], [1, 2]) - Tuple with single element should add trailing comma
tupSingle = (a,) - Sets
- Example: a = set([1, 2, 3])
- No element duplicate
- Example: 1 in a , Output: True (Fast testing)
- Mutable
- Dictionary
- Pretty similar to associative arrays in PHP
- {} -> Empty dict
- Mutable
- Example: cord = {'x' : 123.4, 'y' : 278.5}
- Get keys -> cord.keys() -> return list ['x', 'y']
- Fast Testing -> 'in'
[Python] __main__ and __name__
A module in python (usually in form of .py) will be executed by Python interpreter, we normally face the following situations when running python code.
- Running the .py directly, like python manage.py
- Imported from another module, like from admin import manage.py
So how do python know whether the module is directly run as a main program or it is just a part of another module? The special variable __name__ will do the job!
Take a look at this piece of code
if __name__ == '__main__':
print 'I am run by itself'
else:
print 'I am imported as module'
So if the .py is being run as a main program, the __name__ will have value __main__ being set, otherwise, the __name__ 's value will become the module name itself. We can therefore deal with different situations depending on the program's executing behaviour.
訂閱:
文章 (Atom)