This file contains 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 flask import request | |
@app.route('/data') | |
def data(): | |
# here we want to get the value of user (i.e. ?user=some-value) | |
user = request.args.get('user') |
This file contains 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
# $ pip install pyserial | |
import serial | |
ser = serial.Serial('/dev/tty.usbmodem1411') # open serial port | |
while True: | |
x = ser.read() | |
print(int(ord(x))) # print received byte as int value | |
This file contains 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
>>> INSTALL | |
pip3.4 install weasyprint | |
>>> EXAMPLE | |
from weasyprint import HTML, CSS | |
html_src=''' | |
<h1>The title</h1> | |
<p>Content goes here |
This file contains 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 easy_install pip |
This file contains 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 argument mode points to a string beginning with one of the following | |
sequences (Additional characters may follow these sequences.): | |
``r'' Open text file for reading. The stream is positioned at the | |
beginning of the file. | |
``r+'' Open for reading and writing. The stream is positioned at the | |
beginning of the file. | |
``w'' Truncate file to zero length or create text file for writing. |
This file contains 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
require 'yaml' | |
$db_file = 'filename.yaml' | |
def load_data | |
text = File.read 'db.yaml' | |
return YAML.load text | |
end | |
def store_data hash |
This file contains 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
directory_name = "name" | |
Dir.mkdir(directory_name) unless File.exists?(directory_name) | |
This file contains 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
-- FOR MySQL -disable safemode | |
SET SQL_SAFE_UPDATES = 0; | |
-- for example remove all older than '2014-10-01' | |
DELETE FROM `base-name`.`table-name` WHERE `table-name`.`date-field` < '2014-10-01'; |
This file contains 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
require 'csv' | |
csv_text = File.read('filename.csv') | |
csv = CSV.parse(csv_text, :headers => true) | |
csv.each do |row| | |
Model.create!(row.to_hash) | |
end |
This file contains 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
# in excel: file->import->CSV file | |
require 'csv' | |
# write csv | |
CSV.open("file.csv", "wb") do |csv| | |
csv << ["row", "of", "CSV", "data"] | |
csv << ["another", "row"] | |
# ... | |
end |
NewerOlder