Skip to content

Instantly share code, notes, and snippets.

View bryder's full-sized avatar

Bill Ryder bryder

View GitHub Profile
@bryder
bryder / arrow_samples.py
Last active February 16, 2017 20:08
Using arrow
# 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)
@bryder
bryder / mocking_anotherservice_with_spring.java
Created September 15, 2016 03:25
How to mock another service used in a class you are testing when using spring
// 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 {
- vars:
ansible_added_line: "# Line added by ansible "
nofile_limits:
- user: root
limits:
- soft: 65001
- hard: 70001
- user: some_user
limits:
- soft: 65001
@bryder
bryder / shut_up_elastic_loggin.py
Last active May 22, 2017 21:28
Shut up elastic debug logging if you change it globally and disable warnings about insecure ssl etc
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)
@bryder
bryder / get-vid-pid.ps1
Created June 4, 2016 21:23
get vid and pids from windows usb list in poweshell
$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)}
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'):
def add_template(cli_args, es):
template = {
'template': cli_args.elastic_index_prefix + '*',
'mappings': {
"_default_": {
'dynamic_templates': [
{ 'string_fields': {
'match': '*',
'match_mapping_type': 'string',
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%%.*}
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 @-
- 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