Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrii Havryliuk h1k3r

View GitHub Profile
@h1k3r
h1k3r / elastic_search_delete_empty_indexes.sh
Created Feb 3, 2021
elastic_search_delete_empty_indexes.sh
View elastic_search_delete_empty_indexes.sh
#!/bin/bash
# Based on https://discuss.elastic.co/t/finding-and-deleting-empty-indexes/172764
# Usage:
# elastic_search_delete_empty_indexes.sh servername:9200 #for dry run
# elastic_search_delete_empty_indexes.sh servername:9200 delete #to really delete
srv=""
delete=false
@h1k3r
h1k3r / anonymizeIp.php
Created Aug 2, 2016
Anonymize IP according like Google Analytics (according to German laws)
View anonymizeIp.php
<?php
/**
* Last byte for IPv4 and last 80 bits for IPv6 are set to zero
* @see https://support.google.com/analytics/answer/2763052?hl=en
*/
function anonymizeIp($ip)
{
$binary = inet_pton($ip);
if ($binary === false) {
return false;
@h1k3r
h1k3r / detectUrls.js
Created Sep 19, 2014
Js function to extract urls from text (with silly regexp)
View detectUrls.js
var detectUrls = function(text) {
var pattern = /(?:^|[\s\n\r])((?:https?:\/\/|www\.)[^\s\n\r]+)/ig,
urls = [],
matches;
while ((matches = pattern.exec(text)) !== null) {
urls.push(matches[1]);
}
return urls;
};
@h1k3r
h1k3r / getElementsByClassName.js
Created Jul 16, 2014
Cross-browser js function to retrieve elements by classname from dom. Based on prototype js code
View getElementsByClassName.js
var getElementsByXPath = function(xpath, parentElement) {
var xpathResult = document.evaluate(xpath, parentElement, null, XPathResult.ANY_TYPE, null);
var results = [];
var element = xpathResult.iterateNext();
while(element) {
results.push(element);
element = xpathResult.iterateNext();
}
return results;
}
@h1k3r
h1k3r / hostname.lua
Created Jun 25, 2014
Lua - get hostname
View hostname.lua
local _M = {}
function _M.getHostname()
local f = io.popen ("/bin/hostname")
local hostname = f:read("*a") or ""
f:close()
hostname =string.gsub(hostname, "\n$", "")
return hostname
end
return _M