Skip to content

Instantly share code, notes, and snippets.

View bigcraig's full-sized avatar
🎯
Focusing

Craig Woollett bigcraig

🎯
Focusing
View GitHub Profile
"""Extract nested values from a JSON tree."""
def json_extract(obj, key):
"""Recursively fetch values from nested JSON."""
arr = []
def extract(obj, arr, key):
"""Recursively search for values of key in JSON tree."""
if isinstance(obj, dict):
@benhysell
benhysell / gist:10c1eb546bd3401ee50f
Created January 28, 2015 03:08
c# HttpClient Ignore Certificate - for local certificates
using (var client = new HttpClient())
{
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
var response = await client.GetAsync(reqUrl);
response.EnsureSuccessStatusCode();
if (!Convert.ToBoolean(await response.Content.ReadAsStringAsync()))
throw new Exception("Response from webserver was false.");
}
@allanmc
allanmc / genieacs-install.sh
Last active August 3, 2019 08:43
Install GenieACS on Ubuntu 14.04
#!/bin/sh
set -e
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo add-apt-repository -y ppa:chris-lea/redis-server
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-add-repository -y ppa:brightbox/ruby-ng
sudo apt-get -qq update
@derekp7
derekp7 / gist:9978986
Last active May 11, 2024 04:10
RPC in Bash (rpcsh)

Let's say you have a Bash shell script, and you need to run a series of operations on another system (such as via ssh). There are a couple of ways to do this.

First, you can stage a child script on the remote system, then call it, passing along appropriate parameters. The problem with this is you will need to manually keep the remote script updated whenever you change it -- could be a bit of a challenge when you have something to execute on a number of remote servers (i.e., you have a backup script running on a central host, and it needs to put remote databases in hot backup mode before backing them up).

Another option is to embed the commands you want to run remotely within the ssh command line. But then you run into issues with escaping special characters, quoting, etc. This is ok if you only have a couple commands to run, but if it is a complex piece of Bash code, it can get a bit unwieldy.

So, to solve this, you can use a technique called rpcsh -- rpc in shell script, as follows:

First, place th