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 division | |
| import picamera | |
| import picamera.array | |
| import numpy as np | |
| class MyAnalysis(picamera.array.PiRGBAnalysis): | |
| def __init__(self, camera): | |
| super(MyAnalysis, self).__init__(camera) | |
| self.frame_num = 0 |
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
| CASE WHEN ContractPrice < DiscountPrice | |
| THEN | |
| CASE WHEN ContractPrice < ListPrice THEN ContractPrice ELSE ListPrice END | |
| ELSE | |
| CASE WHEN DiscountPrice < ListPrice THEN DiscountPrice ELSE ListPrice END | |
| END |
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
| CREATE VIEW some_dates AS | |
| WITH RECURSIVE dates(i, d) AS ( | |
| VALUES (1, DATE('1970-01-01')) | |
| UNION ALL | |
| SELECT i + 1, d + 1 DAY FROM dates WHERE d < DATE('2070-12-31') | |
| ) | |
| SELECT | |
| d.d AS a_date, | |
| YEAR(d.d) AS a_year, | |
| MONTH(d.d) AS a_month, |
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 gpiozero import RyanteckRobot, Button | |
| from signal import pause | |
| robot = RyanteckRobot() | |
| button_actions = { | |
| Button(26): robot.forward, | |
| Button(16): robot.left, | |
| Button(21): robot.right, | |
| Button(20): robot.backward, |
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
| WITH qdps_with_rows AS ( | |
| SELECT | |
| ROW_NUMBER() OVER (PARTITION BY q.product_code) AS row_num, | |
| q.* | |
| FROM qdps q | |
| ) | |
| SELECT | |
| p.product_code, | |
| SUM(CASE WHEN q.row_num = 1 THEN q.value END) AS qdp1, | |
| SUM(CASE WHEN q.row_num = 2 THEN q.value END) AS qdp2, |
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
| #!/usr/bin/env python | |
| import json | |
| from itertools import izip, cycle, groupby | |
| from operator import itemgetter, attrgetter | |
| # Imagine this is the result of some DB query like: | |
| # SELECT region, year, value FROM some_table ORDER BY region, year | |
| data = [ | |
| ('Southwark', 2009, 71.89), |
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
| def process_iis_directory(d): | |
| print('Processing IIS directory %s' % d) | |
| for entry in os.listdir(d): | |
| entry = os.path.join(d, entry) | |
| if entry.endswith('.gz'): | |
| print('Processing %s into CSV' % entry) | |
| with gzip.open(entry, 'rb') as uncompressed, \ | |
| io.BufferedReader(uncompressed) as buffered, \ | |
| io.TextIOWrapper(buffered, encoding='latin1') as infile, \ | |
| io.open(os.path.splitext(entry)[0] + '.csv', 'wb') as outfile, \ |
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
| def factorial(i): | |
| if i > 1: | |
| return factorial(i - 1) * i | |
| elif i == 1: | |
| return 1 | |
| else: | |
| raise ValueError('Cannot take factorial of %d' % i) | |
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 gpiozero import TrafficLights | |
| from time import sleep | |
| from itertools import cycle, chain | |
| from signal import pause | |
| lights = TrafficLights(12, 16, 19, pwm=True) | |
| def slow(gen): | |
| for item in gen: | |
| yield item |
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 ( | |
| unicode_literals, | |
| absolute_import, | |
| print_function, | |
| division, | |
| ) | |
| from itertools import tee | |
| from collections import deque | |
| from time import sleep |
OlderNewer