Skip to content

Instantly share code, notes, and snippets.

View Rudis1261's full-sized avatar

Rudi Strydom Rudis1261

View GitHub Profile
@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 = "";
@Rudis1261
Rudis1261 / PHP.sublime-settings
Last active August 29, 2015 14:03
Sublime Preference
{
"word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?"
}
@Rudis1261
Rudis1261 / convert_to_720p.sh
Created July 12, 2014 16:26
A quick video conversion script, $1 is the input Video and $2 the output video name.
#!/usr/bin/sh
#ffmpeg -i $1 -vf scale=-1:480 -b:v 500k -maxrate 500k -crf 23 -c:a mp3 -strict -2 -b:a 128k $2
#ffmpeg -i $1 -codec:v libx264 -profile: high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -codec:a mp3 -b:a 128k $2
#ffmpeg -i $1 -codec:v libx264 -profile:v main -preset slow -b:v 400k -maxrate 400k -bufsize 800k -vf scale=-1:480 -threads 4 -codec:a mp3 -b:a 128k $2
ffmpeg -i $1 -codec:v libx264 -profile:v main -preset slow -b:v 1500k -maxrate 1500k -bufsize 2000k -vf scale=-1:720 -threads 4 -codec:a mp3 -b:a 96k $2
@Rudis1261
Rudis1261 / ga_url_tracking_via_gtm.js
Last active August 29, 2015 14:16
This is to be able to inspect the url query string and send the details to Google Analytics through Google Tag Manager
<script type="text/javascript">
/*eslint-env browser*/
/*global ga*/
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
@Rudis1261
Rudis1261 / install-sublime-text.sh
Last active August 29, 2015 14:17
An adaptation of the sublime text 3 installer found here http://www.simonewebdesign.it/install-sublime-text-3-on-fedora-20/
#!/bin/sh
# Sublime Text 3 install with Package Control
# http://simonewebdesign.it/blog/install-sublime-text-3-on-fedora-20/
curl -o ~/st3.tar.bz2 $1
if tar -xf ~/st3.tar.bz2 --directory=$HOME; then
sudo mv ~/sublime_text_3/ /opt/
sudo ln -s /opt/sublime_text_3/sublime_text /bin/sublime
fi
@Rudis1261
Rudis1261 / center_crop.sh
Created March 25, 2015 06:57
Center Cropping images with ImageMagick
echo "Creating thumbnail of ${1}, to ${2}"
echo "Dimensions: ${3}px X ${4}px"
convert $1 -format png -strip -resize $3'x'$4'^' -gravity center -crop $3x$4'+0+0' $2
@Rudis1261
Rudis1261 / test.go
Last active August 29, 2015 14:19
Go Lang Testing Number Divisibilities
package main
import "fmt"
func main() {
for i := 1; i < 100; i++ {
if i %2 == 0 && i %3 == 0 && i %4 == 0 {
fmt.Println(i)
}
}
}
@Rudis1261
Rudis1261 / delete_all_contacts.php
Created May 15, 2015 11:28
Shell Script to Delete all Magento Contacts
<?php
// Delete all users from the database
// Can only be run from the command line
if (! isset($_SERVER['argv'][0])) {
header("HTTP/1.1 403 Unauthorized");
die("Access Denied");
}
// Otherwise make sure the user confirmed