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
Rob Pike's 5 Rules of Programming | |
Rule 1. You can't tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is. | |
Rule 2. Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest. | |
Rule 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.) | |
Rule 4. Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures. | |
Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming. | |
Pike's rules 1 and 2 restate Tony Hoare's famous maxim "Prematur |
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
func RC4(🔏:[UInt8], 🔑:[Int]) -> [UInt8] | |
{ | |
var i = 0, j = 0, S = Array(0...255) | |
for i in 0...255 { | |
j = (j + S[i] + 🔑[i % 🔑.count]) % 256 | |
(S[j], S[i]) = (S[i], S[j]) | |
} | |
i = 0; j = 0 | |
return 🔏.map { | |
i = (i + 1) % 256; j = (j + S[i]) % 256 |
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
#!/usr/bin/python # Usage: rsa.py exponent modulus < plaintext > ciphertext | |
from sys import*;from string import*;a=argv;[s,p,q]=filter(lambda x:x[:1]!= | |
'-',a);d='-d'in a;e,n=atol(p,16),atol(q,16);l=(len(q)+1)/2;o,inb=l-d,l-1+d | |
while s:s=stdin.read(inb);s and map(stdout.write,map(lambda i,b=pow(reduce( | |
lambda x,y:(x<<8L)+y,map(ord,s)),e,n):chr(b>>8*i&255),range(o-1,-1,-1))) |
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
home | |
clearscreen | |
setheading 80 | |
arc 320 90 | |
setheading 105 | |
arc 295 60 | |
setheading 0 | |
pendown | |
forward 15 | |
setheading 90 |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
pip install networkx distance pattern | |
In Flipboard's article[1], they kindly divulge their interpretation | |
of the summarization technique called LexRank[2]. |
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
body | |
{ | |
font-family: HelveticaNeue-Medium, "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: large; | |
background-color: #252b6f; | |
color: white; | |
text-align: center; | |
} | |
a, a:visited, a:hover { color: white; } |
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
float inv_sqrt(float x) | |
{ | |
union { float f; uint32 u; } y = {x}; | |
y.u = 0x5F1FFFF9ul - (y.u >> 1); | |
return 0.703952253f * y.f * (2.38924456f - x * y.f * y.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
Expression related optimizations: Constant Folding, Constant Propagation, Global Propagation, Strength Reduction, Common Subexpression Elimination, Partial Redundancy Elimination, Induction Variable Elimination, Reassociation | |
Loop related optimizations: Loop Invariant Code Motion, Loop Peeling, Loop Unrolling, Loop Distribution, Loop Autoparallelization, Loop Fusion, Loop Fission, Loop Interchange, Loop Tiling/Stripmining, Vectorization, Scalarization | |
Memory/cache related optimizations: Cache blocking, False Sharing Elimination, Structure Peeling, Structure Splitting, Array Contraction, Multi-dimensional Array Dimension Reordering | |
Control flow related optimizations: Code block re-ordering (by frequency), Branch prediction (by static analysis/feedback guided), Code hoisting/sinking (to optimize CPU pipeline), Automatic Inlining, Tail Call Optimization | |
Code generation related optimizations: Register allocation (np complete), Peephole optimization, Superoptimization (no one really does this yet, but cool nonethe |
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
permute_list = (list) -> | |
if list.length <= 1 | |
return [ list ] | |
permutations = [] | |
for first, i in list | |
restOfList = list.slice() | |
restOfList.splice(i, 1) | |
for subperm in permute_list(restOfList) | |
permutations.push([ first ].concat(subperm)) | |
return permutations |
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
command alias pwin expression -o -- (NSString *)[[UIWindow keyWindow] recursiveDescription] |