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
''' | |
PROBLEM: | |
How many 3-letter prefixes are commonly used in English? | |
MOTIVATION: | |
The Lumosity word game constantly tests my vocabulary and ability to | |
remember simple, common words. I would like to improve my performance. | |
SOLUTION: | |
Count the n-letter prefixes used in a dictionary. |
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 the node.js intro tutorial (http://nodejs.org/), they show a basic tcp | |
server, but for some reason omit a client connecting to it. I added an | |
example at the bottom. | |
Save the following server in example.js: | |
*/ | |
var net = require('net'); |
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
<!doctype html> | |
<!-- Note: These days I use JS Bin / JSFiddle if a snippet requires more than a few lines, or running JavaScript. --> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>foo</title> | |
<style type="text/css"> |
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
""" | |
Simply display the contents of the webcam with optional mirroring using OpenCV | |
via the new Pythonic cv2 interface. Press <esc> to quit. | |
""" | |
import cv2 | |
def show_webcam(mirror=False): | |
cam = cv2.VideoCapture(0) |
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
function archive_all(testOnly) { | |
var someMessages, archiveButton; | |
if (testOnly === "undefined") { testOnly = false; } | |
someMessages = $("li._k- span.accessible_elem"); | |
console.log("Found", someMessages.length, "messages to archive in your inbox."); | |
archiveButton = null; | |
someMessages.each(function () { |
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
""" | |
Fizz buzz "one liner". | |
Disclaimer: I don't write code like this for real. Python 2/3. | |
""" | |
from __future__ import print_function | |
def fizz_buzz(start=1, end=100, word1='Fizz', word2='Buzz'): [print(' '.join([word1, word2]) if i % 3 == 0 and i % 5 == 0 else (word1 if i % 3 == 0 else (word2 if i % 5 == 0 else i))) for i in range(start, end + 1)] | |
if __name__ == '__main__': |
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
python -m cProfile -s tottime foo.py |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
def join_plus(items, separator, final_separator=None, pair_separator=None): | |
"""Concatenate a list of items with more advanced separator control. | |
Example 1 - You have a list of names = [Tom, Jeff, Sally] and want them | |
combined as a string. There are a few possible desired outputs: | |
(1-1) Tom, Jeff, Sally # join_plus(names, ', ') | |
(1-2) Tom, Jeff, and Sally # join_plus(names, ', ', final_separator=', and ') | |
Example 2 - Same but with two names = [Tom, Jeff]. This creates a third |
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
""" | |
Generate ordinal days for a given year. | |
January 1st, January 2nd, January 3rd ... December 31st. | |
""" | |
import calendar | |
import datetime | |
def suffix(day): |
OlderNewer