with a hat tip to Sublime Text 2 Shortcuts
| ⌘; | autocomplete |
| ⌘⌥B | instant replay |
| ⌘⌥E | search across all tabs |
| import random | |
| import timeit | |
| from copy import deepcopy | |
| def inter_reduce(sets): | |
| return reduce(set.intersection, sets) | |
| def inter_for_deepcopy(sets): | |
| sets = iter(sets) | |
| result = deepcopy(next(sets)) |
| class ComparableMixin: | |
| def __eq__(self, other): | |
| return not (self < other or other < self) | |
| def __le__(self, other): | |
| return not other < self | |
| class Foo(ComparableMixin): | |
| def __init__(self, val): | |
| self.val = val |
| ''' | |
| Example showing that isinstance checks are faster than doing a "it's better to ask for forgiveness than | |
| permission approach. | |
| ''' | |
| from timeit import Timer | |
| # Silly timing code that can be ignored | |
| def timeruns(runs, num_iterations = 100): | |
| return [(label, Timer(cmd, imports).timeit(num_iterations)) |
| from timeit import Timer | |
| if __name__ == "__main__": | |
| setup = 'x = list(range(100000))' | |
| num_iter = 1000 | |
| print(Timer('sum(1 for item in x if item % 2 == 0)', setup).timeit(num_iter)) | |
| print(Timer('len([item for item in x if item % 2 == 0])', setup).timeit(num_iter)) | |
| # prints (on my machine): | |
| # 12.4215... |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class TestTest implements Runnable { | |
| public static void main(String [] args) throws InterruptedException { | |
| List<Thread> threads = new ArrayList<Thread>(); | |
| for (int x = 0; x < 10; x++) { |
| import sys | |
| lines = [] | |
| for i in range(1, len(sys.argv)): | |
| lines.append("================================== START OF sys.argv%s==========================\n" % i) | |
| with open(sys.argv[i]) as fobj: | |
| for line in fobj: | |
| lines.append(line.decode('utf-8')) | |
| lines.append("================================== END OF sys.argv%s==========================\n" % i) |
| private static File tmpDir; | |
| @BeforeClass | |
| public static void setUp() { | |
| String dirname = UUID.randomUUID().toString().replace("-", ""); | |
| tmpDir = new File(System.getProperty("java.io.tmpdir"), dirname); | |
| if (!tmpDir.exists()) { | |
| tmpDir.mkdir(); | |
| } | |
| } |
| <mx:DataGrid id="myGrid" | |
| editable="true" | |
| itemEditBeginning="disableEditing(event)"> | |
| <!-- definition of columns & such here --> | |
| </mx:DataGrid> |
| <?xml version="1.0"?> | |
| <!-- itemRenderers\events\EndEditEventPreventEdit.mxml --> | |
| <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" | |
| xmlns:s="library://ns.adobe.com/flex/spark" | |
| xmlns:mx="library://ns.adobe.com/flex/mx" | |
| initialize="init()"> | |
| <fx:Script> | |
| <![CDATA[ | |
| import mx.collections.ArrayCollection; |
with a hat tip to Sublime Text 2 Shortcuts
| ⌘; | autocomplete |
| ⌘⌥B | instant replay |
| ⌘⌥E | search across all tabs |