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
(function() { | |
function Revive (evnt) { | |
onEvent = "on" + evnt; | |
if(window.addEventListener) { | |
window.addEventListener(onEvent, function (e) { | |
for (var node = e.originalTarget; node; node = node.parentNode) { | |
[node] = null; | |
} | |
}, true); | |
window[onEvent] = null; |
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 DjangoMethodOverrideMiddleware(object): | |
METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'CONNECT'] | |
def process_request(self, request): | |
method = request.REQUEST.get("_method", None) | |
if method is None: | |
return | |
else: | |
method = method.upper() | |
if method in self.METHODS: | |
request.method = method |
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
from django.db import models | |
from jsonfield import JSONField | |
from dirtyfields import DirtyFieldsMixin | |
import time | |
class RecordStatusHistoryMixin(DirtyFieldsMixin): | |
def save(self, *args, **kwargs): | |
if not self.pk: | |
# first create | |
current_time = int(time.time()) |
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
#!/bin/sh | |
# dependencies: find, grep, sort, uniq, awk | |
echo 'List all files...' | |
find $1 | |
# output: | |
# a | |
# a/b | |
# a/b/c | |
# a/b/c/d |
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> | |
#include <iterator> | |
#include <vector> | |
#include <set> | |
// overload for all STL containers | |
template < | |
typename T, | |
typename = typename std::enable_if < | |
std::is_convertible< |
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 | |
# ref. https://medium.com/on-coding/shorter-code-is-inconsiderate-41cce917b51b | |
import timeit | |
setup = ''' | |
def hamming_fp(a, b): | |
return sum(x != y for x, y in map(None, a, b)) | |
def hamming(s1, s2): | |
hamming_number = 0 |
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> | |
template <typename lhs_t, typename func_t> | |
inline func_t operator > (lhs_t const &lhs, func_t rhs) { | |
return rhs; | |
} | |
template <typename rhs_t, typename func_t> | |
inline auto operator < (func_t const &lhs, rhs_t const &rhs) -> decltype(lhs()) | |
{ |
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
// clang++ hello.cpp | |
#include <iostream> | |
template <typename lhs_t, typename rhs_t> | |
inline int operator, (lhs_t lhs, rhs_t b) { | |
std::cout << "飲冰室茶集" << std::endl; | |
return 0; | |
} | |
template <typename lhs_t, typename rhs_t> |
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> | |
#include <type_traits> | |
class Foo { | |
public: | |
int ToString(); | |
}; | |
class Bar { | |
public: |
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
/* bitset.js | |
* | |
* bitset = new Bitset(64); | |
* bitset.toString(); // "0000000000000000000000000000000000000000000000000000000000000000" | |
* bitset.setBit(48, 1).setBit(23, 1).setBit(52, 1); | |
* bitset.toString(); // "0000000000010001000000000000000000000000100000000000000000000000" | |
* bitset.toInt(); // 4785074612469760 | |
* | |
* bitset.fromInt(679642164705874); | |
* bitset.toString(); // "0000000000000010011010100010000110000101110011010011101001010010" |
OlderNewer