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
class Shape(object): | |
def __new__(cls, desc, color='black'): | |
if cls is Shape: | |
if desc == 'sankaku': | |
return super(Shape, cls).__new__(Triangle, color) | |
elif desc == 'shikaku': | |
return super(Shape, cls).__new__(Rectangle, color) | |
else: | |
return super(Shape, cls).__new__(Shape, color) | |
else: |
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
text = 'Test 1' | |
def print_text(): | |
print text |
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 <fcntl.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <unistd.h> | |
typedef unsigned long long uint64_t; | |
int presence(int pagemap_fd, uint64_t address) { | |
uint64_t index = (address / getpagesize()) * 8; |
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 <cstdio> | |
#ifdef DECLARE_PRINTER_ | |
#error "The macro DECLARE_PRINTER_ is duplicated." | |
#else | |
#define DECLARE_PRINTER_(SECTION, VALUE_NAME) \ | |
void print_##SECTION##_##VALUE_NAME() { \ | |
printf("%s - %s\n", #SECTION, #VALUE_NAME); \ | |
} | |
#endif // DECLARE_PRINTER_ |
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 <iostream> | |
enum EntryIds { | |
Entry1, | |
NumberOfEntries | |
}; | |
class EntryBase { | |
public: | |
EntryBase() : entry_id_(NumberOfEntries) {} |
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 <iostream> | |
class Base { | |
public: | |
virtual int func() { | |
return 0; | |
} | |
}; | |
class Derived1 : public Base { |
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 <iostream> | |
class Base { | |
public: | |
virtual void common_func(int arg) { | |
std::cout << "Bas" << arg << std::endl; | |
} | |
}; | |
template <class A> |
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
public class XorByte { | |
public static void main(String[] args) { | |
byte r; | |
byte x = 0x13; | |
byte y = (byte)0x9f; | |
r = x ^ y; | |
System.out.println(r); | |
} | |
} |
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 javax.xml.bind.JAXB; | |
import javax.xml.bind.annotation.XmlElement; | |
import javax.xml.bind.annotation.XmlElementWrapper; | |
import javax.xml.bind.annotation.XmlRootElement; | |
import javax.xml.bind.annotation.adapters.XmlAdapter; | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |
@XmlRootElement(name = "base") | |
interface BaseClass { |
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 org.w3c.dom.Document; | |
import org.w3c.dom.Element; | |
import javax.xml.bind.annotation.adapters.XmlAdapter; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
// XmlAdapter<Object,*> receives XML DOM nodes in org.w3c.dom.Element. | |
public class MyXmlAdapter extends XmlAdapter<Object, TargetClass> { |