This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| #Deletes emails older than this number of days | |
| OLD_THAN_DAYS=30 | |
| if [ ! -d /home/root/Maildir ]; then | |
| continue; | |
| fi | |
| for file in `find /home/root/Maildir -mtime +${OLD_THAN_DAYS} | grep -E '/cur/|/new/'`; do | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Obtenemos todos los productos con stock > 0 | |
| // creo que esto pueda que tenga un pequeño bug y no se si lo tiraria a todos lo productos | |
| class ProductRepository implements ProductRepositoryInterface | |
| { | |
| /** | |
| * @return ArrayCollection | |
| */ | |
| public function get() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # How to merge two dictionaries | |
| # in Python 3.5+ | |
| >>> x = {'a': 1, 'b': 2} | |
| >>> y = {'b': 3, 'c': 4} | |
| >>> z = {**x, **y} | |
| >>> z | |
| {'c': 4, 'a': 1, 'b': 3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # How to sort a Python dict by value | |
| # (== get a representation sorted by value) | |
| >>> xs = {'a': 4, 'b': 3, 'c': 2, 'd': 1} | |
| >>> sorted(xs.items(), key=lambda x: x[1]) | |
| [('d', 1), ('c', 2), ('b', 3), ('a', 4)] | |
| # Or: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The get() method on dicts | |
| # and its "default" argument | |
| name_for_userid = { | |
| 382: "Alice", | |
| 590: "Bob", | |
| 951: "Dilbert", | |
| } | |
| def greeting(userid): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Why Python is Great: Namedtuples | |
| # Using namedtuple is way shorter than | |
| # defining a class manually: | |
| >>> from collections import namedtuple | |
| >>> Car = namedtuple('Car', 'color mileage') | |
| # Our new "Car" class works as expected: | |
| >>> my_car = Car('red', 3812.4) | |
| >>> my_car.color | |
| 'red' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> import this | |
| The Zen of Python, by Tim Peters | |
| Beautiful is better than ugly. | |
| Explicit is better than implicit. | |
| Simple is better than complex. | |
| Complex is better than complicated. | |
| Flat is better than nested. | |
| Sparse is better than dense. | |
| Readability counts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The standard string repr for dicts is hard to read: | |
| >>> my_mapping = {'a': 23, 'b': 42, 'c': 0xc0ffee} | |
| >>> my_mapping | |
| {'b': 42, 'c': 12648430. 'a': 23} # 😞 | |
| # The "json" module can do a much better job: | |
| >>> import json | |
| >>> print(json.dumps(my_mapping, indent=4, sort_keys=True)) | |
| { | |
| "a": 23, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #simple | |
| [f(x) for x in sequence] | |
| #simple with if | |
| [f(x) for x in sequence if condition] | |
| #with if and else condition | |
| [f(x) if condition else g(x) for x in sequence] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Why Python Is Great: | |
| # Function argument unpacking | |
| def myfunc(x, y, z): | |
| print(x, y, z) | |
| tuple_vec = (1, 0, 1) | |
| dict_vec = {'x': 1, 'y': 0, 'z': 1} | |
| >>> myfunc(*tuple_vec) |