Skip to content

Instantly share code, notes, and snippets.

@blowhacker
blowhacker / ipaddress.sh
Created February 25, 2024 19:26
bash to get own ip address, with failover
#!/bin/bash
commands=(
"dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null"
"echo $(curl -s cloudflare.com/cdn-cgi/trace | grep ip= | cut -d= -f2)"
"curl -s ifconfig.me/ip 2>/dev/null"
"curl -s ipinfo.io/ip 2>/dev/null"
"curl -s icanhazip.com 2>/dev/null"
"curl -s checkip.amazonaws.com 2>/dev/null"
"curl -s ipecho.net/plain 2>/dev/null"
@blowhacker
blowhacker / calculate-pi-using-random-numbers.js
Created March 13, 2017 22:10
calculate pi using randomnumbers
//inspired by https://www.youtube.com/watch?v=RZBhSi_PwHU
function calculatePi(n) {
function gcd(a, b) {
if (b === 0) return a;
return gcd(b, a % b);
}
var coprime = 0;
@blowhacker
blowhacker / db.grep.js
Created March 14, 2016 11:10
mongo shell db.grep()
DBCollection.prototype.fields = function fields(rowdepth) {
var fields = {};
if (typeof rowdepth == 'undefined')
depth = 101 * 2;
this.find().limit(rowdepth).sort({
_id: -1
}).forEach(function(x) {
var rowfields = dotNotateFields(x);
for (var i in rowfields) {
fields[i] = rowfields[i];