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
// Boost DFS example on an undirected graph. | |
#include <boost/graph/adjacency_list.hpp> | |
#include <boost/graph/depth_first_search.hpp> | |
#include <iostream> | |
using namespace std; | |
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> MyGraph; | |
typedef boost::graph_traits<MyGraph>::vertex_descriptor MyVertex; | |
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
for ( int x = i; x != s; x = next[x] ) | |
{ | |
// Use x here | |
// next[] might be updated here | |
} |
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 caches a small range of integers (objects) | |
# This is implementation specific and can be discovered easily | |
import platform | |
cacheBegin, cacheEnd = 0, 0 | |
for i in range( -500, 0 ): | |
if i is int(str(i)): | |
cacheBegin = i |
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 random | |
# Random float in [0.0, 1.0) | |
a = random.random() | |
# Random float in [0, 100] | |
b = random.uniform( 0, 100 ) |
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 squareIt( x ): | |
return x * x | |
print( squareIt.__name__ ) # squareIt | |
foo = squareIt | |
print( foo.__name__ ) # squareIt | |
squareIt = lambda x: x * x | |
print( squareIt.__name__ ) # <lambda> |
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
# Infinite sequence generator | |
def sequenceGen(): | |
i = 0 | |
while True: | |
yield i | |
i += 1 | |
g = sequenceGen() | |
print( next( g ) ) # 0 | |
print( next( g ) ) # 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
def foo(): | |
return foo.x | |
print( foo() ) # AttributeError: 'function' object has no attribute 'x' | |
foo.x = 10 | |
print( foo.x ) # 10 | |
print( foo() ) # 10 |
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
x = 1 | |
y = eval( "x + 1" ) # 2 | |
f = eval( "lambda x: x * x" ) | |
g = f( 10 ) # 100 |
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
#include <fstream> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
struct Point | |
{ | |
float _p[ 3 ]; | |
}; |
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
# Replace 'a' with '1', 'b' with '2' and 'c' with '3' | |
table = bytes.maketrans( b"abc", b"123" ) | |
s = "abracadabra" | |
s2 = s.translate( table ) | |
print( s2 ) # 12r131d12r1 |
OlderNewer