- Sacrifice storage for computing time/power: store calculated values and avoid batch job
- Sacrifice best OOP/DRY practice to simplify complexity: avoid having too many levels of inheritance and compositions. The human brain cannot handle too much info.
- Avoid having too many helper/factory files: when modifying one function, we shoudn't need to jump back and forth from many other files.
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 mimetypes | |
| def upload_s3(key, fileobj, bucket_name, cache=999999): | |
| """ | |
| Lots of problems with new boto3 library. Many functions are not documented or wrongly documented | |
| 1. s3.Object.metadata, s3.Object.cache_control, s3.Object.content_type: are read only, gotcha | |
| 2. If you set it with `ExtraArgs={'Metadata':{...}}`, wrong again. Cache-Control will become amz-x-cache-control, | |
| not what you wanted | |
| 3. If you set it with `ExtraArgs={'Cache-Control':'max-age=999'}`, wrong again! They need too be CacheControl and ContentType | |
| """ |
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
| """ | |
| If you try to generate documentations using sphinx's autodoc with models extending mongoengine's Document You are going to have a bad time | |
| 1. The code will call Document.objects and list all the entries in your doc!!! | |
| 2. Your model's fields will inherit the default docstr from Field class if you don't have any comment. The documentation generated is very long and difficult to read | |
| This snippet helps to solve these 2 problems. Insert them into config.py file. | |
| """ | |
| import re | |
| from mongoengine.base.fields import ObjectIdField |
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
| esptool.py --port /dev/tty.wchusbserial1410 --baud 115200 write_flash -fm dio --flash_size=detect 0 esp8266-20171101-v1.9.3.bin | |
| screen /dev/tty.wchusbserial1410 -b115200 |
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 sys | |
| from reportlab.lib.pagesizes import * | |
| from reportlab.lib.styles import getSampleStyleSheet | |
| from reportlab.lib.units import inch | |
| from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, PageBreak | |
| from reportlab.lib.enums import * | |
| from reportlab.pdfbase import pdfmetrics | |
| from reportlab.pdfbase.ttfonts import TTFont |
The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capabilities.  
- CPU: 80 MHz
- Memory: 32 KiB instruction, 80 KiB user data
- Input: 16 GPIO pins
- Power: 3.3V DC
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
| mkdir MyIcon.iconset | |
| sips -z 16 16 Icon1024.png --out MyIcon.iconset/icon_16x16.png | |
| sips -z 32 32 Icon1024.png --out MyIcon.iconset/[email protected] | |
| sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_32x32.png | |
| sips -z 64 64 Icon1024.png --out MyIcon.iconset/[email protected] | |
| sips -z 128 128 Icon1024.png --out MyIcon.iconset/icon_128x128.png | |
| sips -z 256 256 Icon1024.png --out MyIcon.iconset/[email protected] | |
| sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_256x256.png | |
| sips -z 512 512 Icon1024.png --out MyIcon.iconset/[email protected] | |
| sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_512x512.png |
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
| from __future__ import print_function, division | |
| def check_sudoku(arr): | |
| # 9 rows, 9 columns and 9 sub squares | |
| # Each of them need to have all the digits | |
| # Not using bit shifting | |
| alignments = [987654321] * 27 | |
| for i, row in enumerate(arr): | |
| for j, x in enumerate(row): |
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
| sudo yum update | |
| # call amazon-linux-extras to view what packages are available | |
| sudo amazon-linux-extras install nginx1 | |
| sudo systemctl enable nginx.service | |
| sudo systemctl start nginx.service | |
| # gcc and python-devel required for uwsgi |
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
| /* | |
| Based on this gist https://gist.github.com/sabas1080/93115fb66e09c9b40e5857a19f3e7787 | |
| Minor modifications | |
| */ | |
| #include <BLEServer.h> | |
| #include <BLEDevice.h> | |
| #include <BLEHIDDevice.h> | |
| #include <BLE2902.h> |