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 collections import namedtuple | |
| import re | |
| # basic token container | |
| Token = namedtuple("Token", ["tag", "val", "pos", "end"]) | |
| # regex scanner handler | |
| t = lambda tag: lambda sc, val: Token(tag, val, sc.match.start(), sc.match.end()) | |
| def lex(text, rules, ignore_whitespace=True): |
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
| """ | |
| http://effbot.org/zone/simple-iterator-parser.htm | |
| http://en.wikipedia.org/wiki/Recursive_descent_parser | |
| ============================================================================== | |
| This is waaaaaayyy longer and much more complicated than it needs to be, | |
| but I have an obsession with abstraction and I'd rather make something | |
| comprehensive and useful than something that just works | |
| ============================================================================== | |
| Cameron Phillips - Jan 2014 - python 3.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
| #include <stdio.h> | |
| #include <time.h> | |
| #define SECOND 1 | |
| #define MINUTE 60 | |
| #define HOUR 3600 | |
| int diff = 0; | |
| void show(int unit, char 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
| #include <Time.h> | |
| int leds[6] = {13, 12, 11, 10, 9, 8}; | |
| void show(int value, int pins[]); | |
| void setup() { | |
| for (int i = 0; i < 6; i++) { | |
| pinMode(leds[i], OUTPUT); | |
| } |
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
| # ---------------------------------------------------------------------------- | |
| # Download the subtitles for the selected movie file from thesubdb.com | |
| # Note: requires requests (https://github.com/kennethreitz/requests) because | |
| # urllib is a pain in the arse | |
| # Date: 02/02/2014 | |
| # Python version: 3.3 | |
| # ---------------------------------------------------------------------------- | |
| import requests | |
| import hashlib | |
| import json |
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 msum(l): | |
| "Product of elements in l" | |
| x = 1 | |
| for i in l: | |
| x *= i | |
| return x | |
| def make_blocks(s, size): | |
| "Create blocks from s of specified size" | |
| for i in range(0, len(s), size): |
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
| """ | |
| http://www.problemotd.com/problem/balancing-act/ | |
| ------------------------------------------------------------------------------ | |
| Problem: You are given 9 balls and a balance scale. One of the balls weighs | |
| slightly less than the other 8. Using the scale only twice how can you figure | |
| out which ball weighs less than the others? Do not attempt to mark the ball | |
| once you find it. | |
| ------------------------------------------------------------------------------ | |
| find the smallest of 9 items only accessing the 'scales' twice | |
| ------------------------------------------------------------------------------ |
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <ctype.h> | |
| typedef float st_type; | |
| typedef struct { | |
| st_type value; | |
| struct node_t *next; | |
| } node_t; |
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 turtle | |
| def shape(turtle, num_sides, side_length, colors=None): | |
| if colors is None: | |
| colors = ["black"] | |
| angle = 360/num_sides | |
| for i in range(3): | |
| turtle.forward(side_length) | |
| turtle.pencolor(colors[i%len(colors)]) | |
| turtle.lt(angle) |
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
| #include <windows.h> | |
| #include <stdio.h> | |
| #include <time.h> | |
| main() { | |
| // keep track of the time | |
| time_t t_start, t_now, t_lastkey; | |
| time(&t_start); | |
| time(&t_now); | |
| time(&t_lastkey); |