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
# http://arrow.readthedocs.io/en/latest/ | |
# when you to('local') you are taking utc and applying the localtime offset | |
# to it - and adding the local timezone descriptor to the object | |
now = arrow.utcnow().to('local') | |
# plural means add or subtract from | |
# singular means set to | |
# nice! | |
two_days_ago_rounded = now.replace(days=-2, hour=0, minute=0, second=0, microsecond=1) |
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
// http://stackoverflow.com/questions/2457239/injecting-mockito-mocks-into-a-spring-bean | |
// Given this service somewhere | |
@Service | |
public class MyService { | |
@Autowired | |
private MyDAO myDAO; | |
public void someMethod() throws SomeExecption { | |
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
- vars: | |
ansible_added_line: "# Line added by ansible " | |
nofile_limits: | |
- user: root | |
limits: | |
- soft: 65001 | |
- hard: 70001 | |
- user: some_user | |
limits: | |
- soft: 65001 |
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
logging.getLogger('elasticsearch.trace').setLevel(logging.WARNING) | |
logging.getLogger('elasticsearch').setLevel(logging.WARNING) | |
import urllib3 | |
urllib3.disable_warnings() # Gets some of the warnings - but not the one from elasticsearch | |
with warnings.catch_warnings(): | |
warnings.filterwarnings("ignore", ".*using SSL with verify_certs=False is insecure.*") | |
es = elasticsearch.Elasticsearch(url, retry_on_status=[503, 504, 401], **kwargs) | |
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
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | where {( $_.Description -match "storage" -or $_.Description -match "usb") -and $_.Description -notmatch "hub"} | |
$regex = '.*VID_(?<vid>[0-9A-F]{4})&PID_(?<pid>[0-9A-F]{4}).*' | |
$usb_devices | foreach { if ($_.deviceid -match $regex) { add-member -inputobject $_ @{VID=$matches['vid']; PID=$matches['pid']} -passthru } else { $_ }} | sort pnpclass,name | ft Name, manufacturer, pnpclass, deviceid, vid, pid | |
# some variatinos on select the devices | |
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | where {( $_.Description -match "storage" -or $_.Description -match "usb") -and $_.Description -notmatch "hub"} | |
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | where { $_.Description -notmatch "hub"} | |
$usb_devices = gwmi Win32_USBControllerDevice | %{[wmi]($_.Dependent)} |
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
def transform_some_stuff(data, idx_and_doc_type): | |
# This is mostly copied out of expand_action in the elasticserarch helpers thing - | |
# which is why there's a bunch of keys I don't use in there. | |
# But I'm just leaving them in anyways | |
data = data.copy() | |
op_type = data.pop('_op_type', 'index') | |
action = {op_type: {}} | |
for key in ('_index', '_parent', '_percolate', '_routing', '_timestamp', | |
'_ttl', '_type', '_version', '_version_type', '_id', '_retry_on_conflict'): |
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
def add_template(cli_args, es): | |
template = { | |
'template': cli_args.elastic_index_prefix + '*', | |
'mappings': { | |
"_default_": { | |
'dynamic_templates': [ | |
{ 'string_fields': { | |
'match': '*', | |
'match_mapping_type': 'string', |
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
Reference: http://tldp.org/LDP/LG/issue18/bash.html | |
Given: | |
foo=/tmp/my.dir/filename.tar.gz | |
We can use these expressions: | |
path = ${foo%/*} | |
To get: /tmp/my.dir (like dirname) | |
file = ${foo##*/} | |
To get: filename.tar.gz (like basename) | |
base = ${file%%.*} |
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
cat get_job_totals.no_beauty_exrs.002 | jq -c ' | |
.[] | { index: { _index: "manuka_xmlstats_by_job", _type: "by_job"}}, | |
.' | curl -XPOST http://escluster:9200/_bulk --data-binary @- |
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
- name: WTF - this works | |
debug: var=item | |
with_items: "{{ nrpe_agent_Debian }}" | |
- name: WTF - this does not work | |
debug: var=item | |
with_items: nrpe_agent_{{ ansible_os_family }} | |
- name: WTF - this does not work 2 | |
debug: var=item |