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 io import StringIO | |
from django.core.files.storage import Storage | |
from django.test import SimpleTestCase as TestCase | |
from override_storages import OverrideStorageMixin | |
# noinspection PyAbstractClass |
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 | |
from __future__ import unicode_literals, print_function, absolute_import, division | |
import os | |
import re | |
import sys | |
from io import StringIO, open | |
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
//: Playground - noun: a place where people can play | |
struct VirtualPrinter: CustomStringConvertible { | |
var sortingIndex: Int | |
let name: String | |
init(name: String, sortingIndex: Int) { | |
self.name = name | |
self.sortingIndex = sortingIndex | |
} |
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 Python and ES6: | |
Iterables: | |
- 有辦法被套在 `for ... in ...` (Python) or `for ... of ...` (ES6) | |
- 可以一直重複被列舉內容 | |
- For Python: 有個 method 叫 `__iter__` 會回傳 iterator | |
- For ES6: 有個 attribute 叫 `Symbol.iterator` 會回傳 iterator | |
Iterators: | |
- 可以有效率(效能跟記憶體使用上)的列舉出 collection 中的內容 |
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 __future__ import absolute_import, division, print_function, unicode_literals | |
from multiprocessing.dummy import Pool as ThreadPool | |
from multiprocessing import Lock | |
from threading import get_ident | |
class SingletonType(type): | |
def __new__(mcs, name, bases, attrs): | |
# Assume the target class is created (i.e. this method to be called) in the main thread. |
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 | |
from __future__ import absolute_import, division, print_function, unicode_literals | |
import pip | |
def reverse_dependency(package_name): | |
rev_dep = [ | |
pkg.project_name for pkg in pip.get_installed_distributions() | |
if package_name in [requirement.project_name for requirement in pkg.requires()] | |
] |
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
#define guard(CONDITION) if (CONDITION) {} |
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 datetime | |
from itertools import permutations | |
def test_body(a, b, c, d, e, f, g, h, i): | |
mul_result = (a*10 + b) * c | |
add_result = mul_result + (f*10 + g) | |
return mul_result == d*10 + e and add_result == h*10 + i | |
now = datetime.datetime.now() |
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
@interface SomeOtherClass : NSObject | |
@end | |
@implementation SomeOtherClass | |
- (void)performAction1:(id)param { | |
if ([param isKindOfClass:[NSNumber class]] || [param isKindOfClass:[NSString class]]) { | |
NSLog(@"%lf", [param doubleValue]); | |
} 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
class E(Exception): | |
def __init__(self, *args, **kwargs): | |
super(E, self).__init__(*args, **kwargs) | |
print('Create exception') | |
def __del__(self): | |
print('Discard exception') | |
def __str__(self): | |
return 'my exception' | |
def f(): |