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.nasuinfo.or.jp/FreeSpace/kenji/sf/python/virtualMachine/PyVM.htm | |
| import dis;import inspect as ins;dis.dis(ins.stack()[1][0].f_code) | |
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
| # The Absolute and Relative Imports has been | |
| # implemented in Python 2.5 | |
| # | |
| # http://docs.python.org/whatsnew/pep-328.html | |
| HAS_RELATIVE_IMPORTS = (sys.hexversion > 0x2050000) | |
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
| # The Absolute and Relative Imports has been | |
| # implemented in Python 2.5 | |
| # | |
| # http://docs.python.org/whatsnew/pep-328.html | |
| HAS_RELATIVE_IMPORTS = (sys.hexversion > 0x2050000) | |
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
| """ | |
| Serve static files from a zip file | |
| """ | |
| from google.appengine.ext import zipserve, webapp | |
| class StaticFileHandler(zipserve.ZipHandler): | |
| def get(self, prefix, filename): | |
| if filename.endswith('/'): |
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> | |
| /** | |
| * Hexadecimal number character to integer | |
| */ | |
| static int c2n(int c) { | |
| return c%87%48; | |
| } | |
| int main(void) { |
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
| /** | |
| * check_pow2: Returns 1 if n is power of 2 | |
| */ | |
| #include <stdio.h> | |
| #include <assert.h> | |
| static int check_pow2(unsigned int n) { | |
| return n != 0 && (n&n-1) == 0; | |
| } | |
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> | |
| int main(void) { | |
| unsigned int ui = 1234; | |
| printf("unsigned int: %u\n", ui); | |
| printf("interpreted as signed int: %d\n", ui); | |
| printf("minus value: %d\n", ~ui + 1); | |
| return 0; |
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
| /** itoa implementation */ | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <assert.h> | |
| static int n2c(int n) { | |
| assert(n >= 0 && n <= 15); | |
| return n <= 9 ? n + '0' : n - 10 + 'a'; | |
| } |
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
| /** | |
| * BridgeCrossing - SRM 146 Div 2 (3rd problem): | |
| * http://www.topcoder.com/stat?c=problem_statement&pm=1599&rd=4535 | |
| */ | |
| import java.util.ArrayList; | |
| import java.util.HashSet; | |
| import java.util.List; | |
| import java.util.PriorityQueue; | |
| import java.util.Queue; | |
| import java.util.Set; |
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
| // % javac Fibonacci.java | |
| // % java -ea Fibonacci | |
| public class Fibonacci { | |
| public static int fib(int n) { | |
| if (n < 0) throw new IllegalArgumentException("n must be more than 0"); | |
| if (n <= 1) return n; | |
| int fib0 = 1; |