- async
- Finish goddamn site
- AppleScript
- caching, memcached
- nginx
- reddis
- Celery
- Fabric
- starlingswarmintelligence port to Python
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
import math | |
# Pythagorean theorem | |
# a² + b² = c² | |
def distance(p, q): | |
return math.sqrt((p[0] - q[0])**2 + (p[1] - q[1])**2) | |
# >>> distance([200, 250], (300, 350)) | |
# 141.4213562373095 |
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
import time | |
def execute_something(): | |
# code | |
time.sleep(60) | |
while True: | |
execute_something() |
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
import threading | |
def f(): | |
print('Hello, World!') | |
# call f() again in 30 seconds | |
threading.Timer(30, f).start() | |
f() |
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
# File: FindDuplicate.py | |
# Author: Keith Schwarz ([email protected]) | |
# | |
# An algorithm for solving the following (classic) hard interview problem: | |
# | |
# "You are given an array of integers of length n, where each element ranges | |
# from 0 to n - 2, inclusive. Prove that at least one duplicate element must | |
# exist, and give an O(n)-time, O(1)-space algorithm for finding some | |
# duplicated element. You must not modify the array elements during this | |
# process." |
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
# File: MatrixFind.py | |
# Author: Keith Schwarz ([email protected]) | |
# | |
# An algorithm for finding a specific value in a specially-formatted matrix of | |
# values. | |
# | |
# The algorithm takes as input a matrix of values where each row and each | |
# column are in sorted order, along with a value to locate in that array, then | |
# returns whether that element exists in the matrix. For example, given the | |
# matrix |
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
# File: KnuthMorrisPratt.py | |
# Author: Keith Schwarz ([email protected]) | |
# | |
# An implementation of the Knuth-Morris-Pratt (KMP) string-matching algorithm. | |
# This algorithm takes as input a pattern string P and target string T, then | |
# finds the first occurrence of the string T in the pattern P, doing so in time | |
# O(|P| + |T|). The logic behind the algorithm is not particularly complex, | |
# though getting it to run in linear time requires a few non-obvious tricks. | |
# | |
# To motivate KMP, consider the naive algorithm for trying to match a pattern |
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
$(document).ready(function() { | |
// AJAX GET | |
$('.get-more').click(function() { | |
$.ajax({ | |
type: "GET", | |
url: "/ajax/more/", | |
success: function(data) { | |
for(i=0; i<data.length; i++) { | |
$('ul').append('<li>'+data[i]+'</li>'); | |
} |
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
# ~/.osx — http://mths.be/osx | |
############################################################################### | |
# General UI/UX # | |
############################################################################### | |
# Set computer name (as done via System Preferences → Sharing) | |
scutil --set ComputerName "MathBook Pro" | |
scutil --set HostName "MathBook Pro" | |
scutil --set LocalHostName "MathBook-Pro" |
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
radio_val = radio_val.toLowerCase().replace(/\b[a-z]/g, function(letter) { | |
return letter.toUpperCase(); | |
}); |
OlderNewer