This file contains hidden or 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 scala.concurrent.{Await, ExecutionContext, Future} | |
| import java.util.concurrent.{ExecutorService, Executors} | |
| import scala.concurrent.duration.DurationInt | |
| val singleThreadedPool: ExecutorService = Executors.newSingleThreadExecutor() | |
| implicit val ec = | |
| concurrent.ExecutionContext.fromExecutorService(singleThreadedPool) | |
| val rand = new scala.util.Random | |
| def merge(message: String): Future[(String, List[String])] = | |
| Future.successful( | |
| message, |
This file contains hidden or 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
| if(!doc.containsKey("log.keyword") || doc['log.keyword'].empty){ | |
| emit(""); | |
| } else { | |
| def log = doc['log.keyword'].value; | |
| if (log != null) { | |
| int closingBracketIndex = log.lastIndexOf(']'); | |
| if (closingBracketIndex > 0) { | |
| emit(log.substring(closingBracketIndex+1)); | |
| return; |
This file contains hidden or 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
| This fails, you cannot update something that is not there | |
| {"update": {"_index":"banana","_id":"dolly"}} | |
| {"doc": {"hello":"dolly"}} | |
| This succeeds, but will always update, even if unchanged. | |
| The version count will increase, and the value of "result" will be "updated" | |
| {"index": {"_index":"banana","_id":"kitty"}} | |
| {"doc": {"hello":"kitty"} |
This file contains hidden or 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
| curl -XGET localhost:9200/_cat/indices 2>/dev/null | sed 's/.*open //' | sed 's/ .*//'| xargs -I % echo curl -XDELETE localhost:9200/% |
This file contains hidden or 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
| // ==UserScript== | |
| // @name Porn-Phil | |
| // @version 1 | |
| // @grant none | |
| // @include https://*.wikipedia.org/* | |
| // ==/UserScript== | |
| // Replace any references to pornography with philanthropy | |
| (function() { |
This file contains hidden or 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
| """ | |
| Using Mock.side_effect with a list to provide multiple return values | |
| """ | |
| from unittest import mock | |
| class MyClass: | |
| @staticmethod | |
| def hello(lang): |
This file contains hidden or 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 timeit import timeit | |
| import string | |
| # If you have a chain of if and elif like this | |
| # that you then use to decide a particular | |
| # course of action | |
| def ifelif(arg1, arg2): | |
| if arg1 == 'hello': | |
| return 'hi ' + arg2 | |
| elif arg1 == 'namaskara': |
This file contains hidden or 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 unittest import mock | |
| | |
| class MyClass: | |
| def __init__(self): | |
| print('hello') | |
| self.my_property = 'dolly' | |
| | |
| def do_something(self): | |
| print('world') | |
| |
This file contains hidden or 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 hudson.plugins.warnings.parser.Warning | |
| String filename = matcher.group(1) | |
| String line = matcher.group(2) | |
| gradeMap = [A:'low - simple block', | |
| B:'low - well structured and stable block', | |
| C:'moderate - slightly complex block', | |
| D:'more than moderate - more complex block', | |
| E:'high - complex block, alarming', | |
| F:'very high - error-prone, unstable block'] | |
| String message = gradeMap.get(matcher.group(4))+ " " + matcher.group(4) + " " + matcher.group(5) |
This file contains hidden or 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
| myproj/myfile.py - B (14.83) |
NewerOlder