dP.  .dP .d8888b. .d8888b. 88d888b. d888888b
 `8bd8'  88'  `"" Y8ooooo. 88'  `88    .d8P'
 .d88b.  88.  ...       88 88        .Y8P   
dP'  `dP `88888P' `88888P' dP       d888888P
    
PROGRAMMER /ˈprōˌɡramər/
A person who solves problems you didn't know you had in ways you don't understand.
public wərk snippets contact

Code Snippets

Mira Milk Frother Usage
  • To warm and froth milk:
Push the on button once
- blue indicator lights up
  • To only warm milk:
Push the on button two time
- blue indicator lights up (not helpful)
  • To only froth milk:
Push the on button three times
- the blue indicator flashes
This python script is used to increase the number of replicas in an ES cluster and force those new replicas to be allocated to a new host to enable a filesystem backup of the ES data directory.
from requests import get, post, put
from json import dumps, loads
from sys import argv
from math import ceil
commands = []
def addShard(idx, shard):
commands.append({
"allocate" : {
"index" : idx,
"shard" : int(shard),
"allow_primary" : False,
"node" : backup_node
}
})
state = loads(get('http://localhost:9200/_cluster/state?filter_metadata=true').content)
data_nodes = []
for node in state['nodes']:
if "data" in state['nodes'][node]['attributes'] and state['nodes'][node]['attributes']['data'] == "false":
continue
data_nodes.append({ 'node': node, 'address': state['nodes'][node]['transport_address']})
replica_count = int(ceil(len(data_nodes)/2.0))
if len(argv) != 2:
print "You must specify which node is the backup node or the 'reset' command. Available nodes right now are:"
for node in data_nodes:
print "\t- %s (%s)" % (node['node'], node['address'])
quit()
if argv[1] == "reset":
put('http://localhost:9200/_settings', data='{ "index.routing.allocation.disable_allocation": false }')
put('http://localhost:9200/_settings', data='{ "index" : { "number_of_replicas" : %d } }' % replica_count)
quit()
backup_node = argv[1]
if backup_node not in state['nodes']:
print "Invalid data node"
quit()
put('http://localhost:9200/_settings', data='{ "index.routing.allocation.disable_allocation": true }')
put('http://localhost:9200/_settings', data='{ "index" : { "number_of_replicas" : %d } }' % (replica_count+1))
for idx in state['routing_table']['indices']:
for shard in state['routing_table']['indices'][idx]['shards']:
addShard(idx, shard)
# this is a lot of output, TODO: consolidate this into just what's useful
print dumps(loads(post('http://localhost:9200/_cluster/reroute?pretty', data=dumps({ "commands": commands })).content), indent=4)
When you need to jump start a material-ui project with the pre-hooks version of react. (react v16.7, material-ui v3.7.1)
curl https://codeload.github.com/mui-org/material-ui/tar.gz/v3.7.1 | tar -xz --strip=2 material-ui-3.7.1/examples/create-react-app
Print the dates from an SSL certificate
openssl x509 -noout -dates -in cert.pem
This one command is so hard to track down every 3 years when I need it. So many posts incorrectly insist the private key is in PEM format already. In truth, it depends on how the key pair was created (openssl vs ssh-keygen).
# NOTE: this updates the file in place, do you have a backup?
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa