Skip to content

Instantly share code, notes, and snippets.

View kasperhartwich's full-sized avatar

Kasper Hartwich kasperhartwich

View GitHub Profile
@kasperhartwich
kasperhartwich / validateImei.php
Created September 7, 2012 08:02
PHP function to validate IMEI numbers.
function validateImei($imei, $use_checksum = true) {
if (is_string($imei)) {
if (ereg('^[0-9]{15}$', $imei)) {
if (!$use_checksum) return true;
for ($i = 0, $sum = 0; $i < 14; $i++) {
$tmp = $imei[$i] * (($i%2) + 1 );
$sum += ($tmp%10) + intval($tmp/10);
}
return (((10 - ($sum%10)) %10) == $imei[14]);
}
@kasperhartwich
kasperhartwich / jquery-exists.js
Created September 13, 2012 07:25
jQuery exists function
//jQuery function to check if element exists.
jQuery.fn.exists = function(){return this.length>0;}
@kasperhartwich
kasperhartwich / array-stristr.php
Created September 20, 2012 10:08
Array stristr version
$illegal_domain_names = array(
'gmail.con',
'gamil.com',
'gail.com',
'gmil.com',
'gmail.co',
'hotnail.com',
'hormail.com',
'hotmail.con',
'hotmil.com',
<?php
function arrayToXml($array, $rootElement = null, $xml = null) {
$_xml = $xml;
if ($_xml === null) {
$_xml = new SimpleXMLElement($rootElement !== null ? $rootElement : '<command/>');
}
foreach ($array as $k => $v) {
if (is_array($v)) {
arrayToXml($v, $k, $_xml->addChild($k));
} else {
@kasperhartwich
kasperhartwich / exec-background.php
Last active December 12, 2015 12:09
Execute command in background with php. For f.ex multithreading.
<?php
function bg_exec($phpfile) {
exec("nohup php " . $phpfile . " >/dev/null 2>&1 & echo $! &");
}
@kasperhartwich
kasperhartwich / speedtest.php
Last active October 24, 2017 21:49
Test by ookla speedtest servers. Needs a cleanup. ;D
#!/usr/bin/php5
<?php
/*
* Speedtest.net linux terminal client.
* This is free and open source software by Alex based on a script from Janhouse
* Script uses curl, executes ifconfig commands in shell and writes temporary files in temp_down folder. Make sure you have everything set up before using it.
*/
header("content-type: text/plain");
/* * * Configuration * * */
$iface="eth0";
@kasperhartwich
kasperhartwich / youtube-play.sh
Created September 4, 2013 14:51
Open youtube video in fullscreen from cli.
#!/bin/sh
open -a "/Applications/Google Chrome.app" "https://www.youtube.com/v/$1&hd=1&autoplay=1"
#!/bin/bash
x=`ping -c1 google.com 2>&1 | grep unknown`
if [ ! "$x" = "" ]; then
echo "$(date +'%F %T') Restarting network" >/var/log/network_monitor.log
service network restart
fi
function ansicolor($text , $color='cyan', $background = false, $bold = false) {
$colorcodes = array('black' => 0, 'red' => 1, 'green' => 2, 'yellow' => 3, 'blue' => 4, 'magenta' => 5, 'cyan' => 6, 'white' => 7);
return ($bold ? chr(27) . "[1m" : "") . chr(27) . "[" . ($background ? '4' : '3') . $colorcodes[$color] . "m" . $text . chr(27) . "[0m";
}
@kasperhartwich
kasperhartwich / hdhomerun-vlc.bat
Created October 19, 2014 20:43
Channelchanger (windows) for HDHomerun found somewhere on the internet..
@echo off
REM Select Channel and Program
set /p _channel=Please enter channel:
set /p _pro=Please enter program:
REM Get your IP address
for /f "delims=[] tokens=2" %%a in ('ping -4 %computername% -n 1 ^| findstr "["') do (set thisip=%%a)
set "str1=udp://"