Instantly share code, notes, and snippets.

View limit-number.py
def limit(num, minimum=1, maximum=255):
"""Limits input 'num' between minimum and maximum values.
Default minimum value is 1 and maximum value is 255."""
return max(min(num, maximum), minimum)
View json-format-using-vim-with-python.md
View ZonedDateTimeAsUTC.java
/*
*
* Methods manipulate milliseconds field (fastTime) in java.util.Date object.
*
* UTC : 12/10/2017 11:15:00
* Local date time : 12/10/2017 14:15:00 +03:00
*
* @return new java.util.Date
* UTC : 12/10/2017 14:15:00
* Local date time : 12/10/2017 17:15:00 +03:00
View pip-install-by-specific-python.sh
pyenv shell 3.6.4 # Shell specific Python version
/usr/local/var/pyenv/versions/3.6.4/bin/python -m pip install -U PACKAGE_NAME
View datagrip-database-connections.md

on macOS

default folder in /Users/USERNAME/Library/Preferences/DataGrip2018.1/projects contains database connection properties.

DataGrip2018.1 states your DataGrip version

View attach-listener-to-push-method.js
var eventify = function(arr, callback) {
arr.push = function(e) {
Array.prototype.push.call(arr, e);
callback(arr);
};
};
var array = [1,2,3];
eventify(array, function(newArray) {
View split-into-subarrays.js
/*
* Splits array into subarrays.
* count parameter indicates that how many item per subarray contains.
* Example usage: splitIntoSubArray([1,2,3,4,5], 2) -> [[1, 2], [3, 4], [5]]
*/
function splitIntoSubArray(arr, count) {
var newArray = [];
while (arr.length > 0) {
newArray.push(arr.splice(0, count));
}
View realtime-tracking-stdout-line-count.sh
docker logs -f --since 2s $(docker ps -qa --filter "name=CONTAINER_NAME") | pv -l -c > /dev/null
View access-static-constant-thymeleaf.md

From expercise project:

<td>
  <input class="form-control" type="text" name="inputValue"
          th:maxlength="${T(com.expercise.utils.Constants).MAX_TESTCASE_VALUE_LENGTH}" />
</td>
View last-records-on-elasticsearch.sh
curl -XGET "http://ES_CLUSTER/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"range" : {
"@timestamp" : {
"gte" : "now-15m",
"lt" : "now"
}
}
}