Como você faria?
Há algumas formas de escrever isso, mas o django-extensions tem algo pronto.
$ ./manage.py show_urls
pronto.
sim, só isso!
=]
$ ./manage.py show_urls
find ./ -type f -newermt 2015-01-01 ! -newermt 2015-08-01 -delete
import requests |
import json |
api_url = 'https://www.googleapis.com/urlshortener/v1/url' |
api_key = 'AIzaSyD-wgUbjlaBOORxF0mrXzeNsOOafKrnw0U' |
url = '{0}?key={1}'.format(api_url, api_key) |
headers = {'content-type': 'application/json'} |
params = json.dumps({'longUrl': 'http://www.google.com'}) |
response = requests.post(url, data=params, headers=headers) |
if response.ok: |
print (response.json()['id']) |
else: |
print (response.status_code, response.reason) |
import pandas as pd
dados = pd.read_csv('file.csv')
dados
a | b | c | d | |
---|---|---|---|---|
0 | 1 | 2 | 3 | 4 |
1 | 5 | 6 | 7 | 8 |
dados.ix[:,1:3]
b | c | |
---|---|---|
0 | 2 | 3 |
1 | 6 | 7 |
dados[['b','d']]
b | d | |
---|---|---|
0 | 2 | 4 |
1 | 6 | 8 |
novo = dados[['b', 'd']]
novo['b']
0 2 1 6
from django import template
register = template.Library()
@register.simple_tag
def template_exists(template_name):
try:
django.template.loader.get_template(template_name)
return u"Template existe"
except template.TemplateDoesNotExist:
return u"Template não existe"
{% template_exists 'algumapp/nome_template.html' %}
$ brew install sdl
$ pip install https://bitbucket.org/pygame/pygame/get/default.tar.gzAqui, caso não tenha instalado o X11, será necessário baixar e instalar XQuartz.
$ lsvirtualenv
import pandas as pd
data = pd.read_excel("arquivo.xls")
data.to_csv("arquivo.csv")
simples assim.import pandas as pd primeiro = pd.read_csv('primeiro.csv') segundo = pd.read_csv('segundo.csv') mesclado = pd.concat([primeiro, segundo], axis=1)
coluna1 | coluna2 | coluna3 | coluna4 | |
---|---|---|---|---|
0 | 1 | a | z | m |
1 | 2 | b | x | n |
2 | 3 | c | c | h |
$ find ~/ -type f -name "error.log"
$ find ~/ -type d -name NOME_PASTA
$ find ./ -type d | grep NOME_PASTA
RewriteEngine on RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
vi +comando NomeArquivoou
vi +numerodalinha NomeArquivoou
vi +/TermoQueVoceProcura NomeArquivo
$ vim +15907 dump.sql
$ vim +/xablau views.py
$ cat ~/.virtualenvs/postactivate #!/bin/bash # This hook is run after every virtualenv is activated.e
$ cat ~/.virtualenvs/postmkvirtualenv #!/bin/bash # This hook is run after a new virtualenv is activated.Os nomes são autoexplicativos, eu diria. Se bem que o comentário do postmkvirtualenv poderia dizer após o virtualenv ser criado.
$ cat ~/.virtualenvs/postmkvirtualenv #!/bin/bash # This hook is run after a new virtualenv is activated. pip install ipython pip install nose pip install coverageE por ai vai.. pode colocar variáveis de ambiente, instalar mais pacotes e etc
$ grep "alguma coisa" -Rn ./ | grep -v essa_pasta_nao
git clone https://github.com/joncasdam/infoq-downloader.git
cd infoq-downloader
pip install -r requirements.txt
E o uso é mais fácil ainda:python infoq_downloader.py http://www.infoq.com/produtividade-e-qualidade-em-python
$ brew search postgres check_postgres homebrew/versions/postgresql9 homebrew/versions/postgresql92 postgres-xc homebrew/versions/postgresql8 homebrew/versions/postgresql91 homebrew/versions/postgresql93 postgresql Caskroom/cask/navicat-for-postgresql Caskroom/cask/postgres
$brew install homebrew/versions/postgresql8Be happy.
from django.http import JsonResponse
return JsonResponse({'foo':'bar'})
from django.http import HttpResponse
return HttpResponse(json.dumps(dados), content_type="application/json")
ruim.py |
bom.py |
from itertools import tee, izip
def pares(lista):
a, b = tee(lista)
next(b, None)
return izip(a, b)
Considerando a lista:lista = [1,2,3,4,5,6,7,8,9,10]
for v, w in pares(lista):
print v, w
1 2
2 3
3 4
...
ou dessa forma:for i in pares(lista):
print i
(1, 2)
(2, 3)
(3, 4)
...
Repare que a função não retorna uma lista, mas um objeto de itertools.$ ping google.com 80
usage: ping [-AaDdfnoQqRrv] [-b boundif] [-c count] [-G sweepmaxsize]
[-g sweepminsize] [-h sweepincrsize] [-i wait] [−k trafficclass]
[-l preload] [-M mask | time] [-m ttl] [-p pattern]
[-S src_addr] [-s packetsize] [-t timeout][-W waittime] [-z tos]
host
$ telnet google.com 80
Trying 74.125.226.48...
Connected to google.com.
Escape character is '^]'.