As configured in my dotfiles.
start new:
tmux
start new with session name:
| /* | |
| The MIT License (MIT) | |
| Copyright (c) 2014 Ismael Celis | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is |
As configured in my dotfiles.
start new:
tmux
start new with session name:
| #!/bin/bash | |
| provider=virtualbox | |
| # Loop over boxes | |
| for box in ~/.vagrant.d/boxes/*; do | |
| # Create provider directory to contain files | |
| mkdir $box/$provider/ |
| M[16],X=16,W,k;main(){T(system("stty cbreak") | |
| );puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i | |
| ,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M | |
| [w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<< | |
| (l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k) | |
| ]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d | |
| -1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X] | |
| *i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4; | |
| )s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4|| | |
| puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2 |
Magic words:
psql -U postgresSome interesting flags (to see all, use -h or --help depending on your psql version):
-E: will describe the underlaying queries of the \ commands (cool for learning!)-l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)| class ObjectList(list): | |
| """A list that can call its objects methods/variables and returns their | |
| own returns in a list. Obviously, the list should contains only one type of | |
| objects. | |
| Example of use: | |
| >>> foo = ObjectList(["bar", "baZ"]) | |
| >>> foo.islower() | |
| [True, False] | |
| >>> foo.append(42) |
| def random_elsewhere_function(): | |
| raise AttributeError("oops") | |
| class Foo(object): | |
| @property | |
| def bar(self): | |
| random_elsewhere_function() | |
| return "bar" |
Normally git diff would color additions green and deletions red. This is cool, but it would be even cooler if it adds syntax highlighting to those lines. This is a git pager that does so.
It parses the diff output and picks up the SHAs of files with additions and deletions. It uses [CodeRay][coderay] to highlight each file and then it extracts the lines that are shown in the diff. It then uses [term/ansicolor][color] to make a gradient from the CodeRay color and the diff color (red for deletion, green for addition) and uses it to replace the original.
I tried using rugged instead of shelling out to git show – it was faster overall, but it did incur a noticeable start up time.
Check out the image below for a demo.
| class Factory(object): | |
| model = object | |
| def __init__(self): | |
| self._objs = {} | |
| def create(self, name): | |
| self._objs[name] = type(name, self.model.__bases__, dict(self.model.__dict__)) | |
| return self._objs[name] |