Skip to content

Instantly share code, notes, and snippets.

View Rudis1261's full-sized avatar

Rudi Strydom Rudis1261

View GitHub Profile
@Rudis1261
Rudis1261 / array_cycle.php
Last active December 26, 2015 18:19
Cycling through arrays without looping through it
<?php
/*
I was faced with a problem where I had to cycle through a list of HTML colors and I thought this was
a nice way of doing it. As array_shift returns the value you remove at the front, simply appending it
to the array does the business. I thought I would share it in-case someone finds it useful.
*/
# We need a list of colors for grouping purposes
$colors = array(
@Rudis1261
Rudis1261 / coming_soon.php
Last active December 26, 2015 18:19
So you want to be able to see what day it is and then fill an array to display something later on. This is how I did it. I am using this to track events happening within the following week. It could be used for a calendar system and so on.
<?php
# Define the days of the week
$days = array(
'Friday',
'Saturday',
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
@Rudis1261
Rudis1261 / array_check_duplicate.php
Created October 28, 2013 09:51
Checking whether an array contains duplicate values or not
<?php
# Let's define a simple array to display the function
$array = array("How", "Now", "Brown", "Cow", "With", "The", "Brown", "Fox");
# Check if it contains a duplicate value?
if ( count($array) !== count(array_unique($array)) )
{
echo "Contains Duplicate";
}
@Rudis1261
Rudis1261 / class.table.php
Last active November 28, 2018 01:25
PHP Tables Class. I use this class to create tables quicker without hand coding out the HTML. We basically treat the arrays are HTML properties=>values.
<?php
# Author: Rudi Strydom
# Date: Aug 2013
# Purpose: Building a quick and dirty table class. To transform an array to a table
class Table
{
public $table_attributes = array();
public $table_heading = array();
@Rudis1261
Rudis1261 / thumber.py
Created November 24, 2013 19:14
Someone else's script which I adapted to remove all the nasty Windows "Thumbs.db" files from my linux media drives.
#!/usr/bin/python
import os
def findNremove(path,pattern,maxdepth=1):
cpath=path.count(os.sep)
for r,d,f in os.walk(path):
if r.count(os.sep) - cpath <maxdepth:
for files in f:
#print files
if files == pattern:
@Rudis1261
Rudis1261 / index.php
Created December 10, 2013 10:00
2nd Factory Authentication. The idea is for a second layer of authentication. This way it's a password which you need to complete a section of. i would possibly rather use a db to track the attempts etc as sessions could possibly be tampered with.
<html>
<head>
<style>
#passwordContainer
{
line-height: 30px;
font-size: 30px;
}
@Rudis1261
Rudis1261 / smstools_eventhandler.php
Last active December 31, 2015 00:39
SMS Tools Event Handler. So the idea to to create an event handler for SMS Tools, which will work in a similar way to a USSD session. User get's the menu with options. We SMS the options back to them. Then they issue a subsequent message to get the information they need back via SMS.
#!/usr/bin/php
<?php
# This function will be used to get the information from the inbound SMS
function decode($string)
{
# Split the text into lines
$lines = explode("\n", $string);
@Rudis1261
Rudis1261 / image.php
Created March 14, 2014 08:38
Script to determine the perceived luminosity of an image. The darker the image the lower the number returned, the lighter the image the higher the number.
<?php
# Function to determine the average luminance of an image
function image_avg_luminance($filename, $num_samples=10, $section="all")
{
# Variables required
$img = imagecreatefromjpeg($filename);
$width = imagesx($img);
$height = imagesy($img);
@Rudis1261
Rudis1261 / index.php
Created March 14, 2014 12:58
Luminosity in practice
<?php
# Function to determine the average luminance of an image
function image_avg_luminance($filename, $num_samples=10, $section="all")
{
# Variables required
$img = imagecreatefromjpeg($filename);
$width = imagesx($img);
$height = imagesy($img);
$x_step = intval($width/$num_samples);
@Rudis1261
Rudis1261 / push.php
Created May 22, 2014 12:36
GeckoBoard List Example
<?php
# DATA
$data_url = "http://rudi.strydom.photography/Portfolio/json/rand";
$get_data = file_get_contents($data_url);
# Geckoboard specifics
$gb_url = "https://push.geckoboard.com/v1/send/";
$gb_token = "";
$gb_api_key = "";