Skip to content

Instantly share code, notes, and snippets.

View dmikurube's full-sized avatar

Dai MIKURUBE dmikurube

View GitHub Profile
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:
@dmikurube
dmikurube / importee1.py
Created January 24, 2014 07:46
Importing a file into a class dynamically
text = 'Test 1'
def print_text():
print text
#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;
#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_
#include <iostream>
enum EntryIds {
Entry1,
NumberOfEntries
};
class EntryBase {
public:
EntryBase() : entry_id_(NumberOfEntries) {}
#include <iostream>
class Base {
public:
virtual int func() {
return 0;
}
};
class Derived1 : public Base {
#include <iostream>
class Base {
public:
virtual void common_func(int arg) {
std::cout << "Bas" << arg << std::endl;
}
};
template <class A>
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);
}
}
@dmikurube
dmikurube / JaxbInheritance.java
Last active August 29, 2015 14:17
JAXB annotations in inheritance
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 {
@dmikurube
dmikurube / MyXmlAdapter.java
Created March 17, 2015 13:30
JAXB Adapter from DOM nodes / elements
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> {