Skip to content

Instantly share code, notes, and snippets.

View h1k3r's full-sized avatar

Andrii Havryliuk h1k3r

View GitHub Profile
@h1k3r
h1k3r / hostname.lua
Created June 25, 2014 19:52
Lua - get hostname
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
@h1k3r
h1k3r / getElementsByClassName.js
Created July 16, 2014 15:37
Cross-browser js function to retrieve elements by classname from dom. Based on prototype js code
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 / detectUrls.js
Created September 19, 2014 15:56
Js function to extract urls from text (with silly regexp)
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 / anonymizeIp.php
Created August 2, 2016 11:49
Anonymize IP according like Google Analytics (according to German laws)
<?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 / elastic_search_delete_empty_indexes.sh
Created February 3, 2021 11:56
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