Welcome to my blog onI force myself to learn at least one new concept or relevant detail per day. This is where I keep track of what I learn so I can review it periodically. Sometimes I put things down that I already know but often forget and I want to use the concepts more often.
sudo su -
echo -e "deb http://apt.puppetlabs.com/ lucid main\ndeb-src http://apt.puppetlabs.com/ lucid main" >> /etc/apt/sources.list.d/puppet.list
apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30
apt-get update
apt-get install -y puppet
On the puppet master run apt-get install -y puppetmaster instead of the last command. Found on the Puppet Ubuntu wiki.
MyObject.save(update_fields=['name'])
git config --global https.proxy https://proxy.url.here:port
git log --diff-filter=D --summary
>>> hex(79)
'0x4f'
>>> bin(56)
'0b111000'
mysql> show tables like 'vizport_%';
+-----------------------------------------+
| Tables_in_your_database (vizport_%) |
+-----------------------------------------+
| vizport_model1 |
| vizport_users |
| vizport_moredata |
+-----------------------------------------+
redis 127.0.0.1:6379> set user:55:username mattmakai
OK
redis 127.0.0.1:6379> get user:55:username
"mattmakai"
git tag v1.5
git push origin v1.5
Also, the git push origin --tags* flag will push all tags.
$ git tag
tag1
tag2
tag3
$ git tag -l "3"
$ git tag -l "\*3"
tag3
I would probably just pipe the git tag output to grep though - it just seems easier to remember.
>>> result = map(lambda x: x * 2, [1, 2, 3])
>>> result
[2, 4, 6]
set foreign_key_checks = 0
sudo add-apt-repository ppa:chris-lea/zeromq
sudo apt-get update
sudo apt-get install zeromq-bin libzmq-dbg libzmq-dev libzmq0
d3.extent([1, 2, 3, 4, 5]); // returns [1, 5]
svg.selectAll("text")
.data(data)
.enter().append("text")
.attr("desired text");
>>> import zlib
>>> a = "hello world this string doesn't need compression but another might"
>>> c = zlib.compress(a)
>>> len(a)
66
>>> len(c)
63
On much larger blocks of text this savings could be more substantial and worth using for serialization over a network connection or saving to a file.
http://en.wikipedia.org/w/api.php?format=json&action=query&list=search&srprop=wordcount&srwhat=text&srlimit=5&srsearch=python
>>> l = [1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10]
>>> l.count(6)
2
>>> a, b = -5, -8.654
>>> abs(a)
5
>>> abs(b)
8.654
>>> a = range(0, 5)
>>> a
[0, 1, 2, 3, 4]
>>> sum(a)
10
>>> d = {}
>>> val = d.get('hello', 'default value')
>>> print val
default value
>>>
The default value is commonly useful with Django when working with GET and POST requests:
# if no user_name in POST, set value to None
username = request.POST.get('user_name', None)
Many context managers are available in Fabric, including:
- cd - change into a specific directory before running a command
- hide - do not show one or more groups of output (i.e. stdout)
- lcd - same as cd but only affects env.lcwd for local commands
- path - append to the system PATH variable
- prefix - prefix all sudo & run commands with a command plus '&&'
- settings - temporarily override environment variables
- show - opposite of hide, show one or more groups of output
:set paste