Skip to content

Instantly share code, notes, and snippets.

View kostasdizas's full-sized avatar

Kostas Dizas kostasdizas

  • Torstone Technology
View GitHub Profile
@kostasdizas
kostasdizas / my-plugin.php
Created November 28, 2010 04:27
create a simple wordpress (2.7+) settings page that includes user options. ( option_two can be different for each user ). The uninstall.php file helps remove all the plugin options.
<?php
// ...
// create custom plugin settings menu
add_action('admin_menu', 'my_plugin_create_menu');
function my_plugin_create_menu() {
@kostasdizas
kostasdizas / jquery.hashQuery.js
Created March 29, 2011 17:35
javascript hash query plugin
(function ($) {
$.hashQuery = {
get: function (key) {
d = {};
$.each(window.location.hash.slice(1).split("&"), function (b, a) {
a !== "" && (a.indexOf("=") !== -1 ? (a = a.split("="), d[a[0]] = a[1]) : d[a] = "")
});
if ($.isEmptyObject(d)) {
return !1
}
@kostasdizas
kostasdizas / check_mail.php
Created May 7, 2011 00:48
advanced e-mail validator
<?php
/**
* Checks if the given e-mail is valid
* Checks Done:
* - Email has correct number of '@' and lengths
* - Domain is valid
* - Domain has too little parts
* - Domain has valid parts
* - Domain is IP
var patterns = '.ach4 .ad4der .af1t .al3t .am5at .an5c .ang4 .ani5m .ant4 .an3te .anti5s .ar5s .ar4tie .ar4ty .as3c .as1p .as1s .aster5 .atom5 .au1d .av4i .awn4 .ba4g .ba5na .bas4e .ber4 .be5ra .be3sm .be5sto .bri2 .but4ti .cam4pe .can5c .capa5b .car5ol .ca4t .ce4la .ch4 .chill5i .ci2 .cit5r .co3e .co4r .cor5ner .de4moi .de3o .de3ra .de3ri .des4c .dictio5 .do4t .du4c .dumb5 .earth5 .eas3i .eb4 .eer4 .eg2 .el5d .el3em .enam3 .en3g .en3s .eq5ui5t .er4ri .es3 .eu3 .eye5 .fes3 .for5mer .ga2 .ge2 .gen3t4 .ge5og .gi5a .gi4b .go4r .hand5i .han5k .he2 .hero5i .hes3 .het3 .hi3b .hi3er .hon5ey .hon3o .hov5 .id4l .idol3 .im3m .im5pin .in1 .in3ci .ine2 .in2k .in3s .ir5r .is4i .ju3r .la4cy .la4m .lat5er .lath5 .le2 .leg5e .len4 .lep5 .lev1 .li4g .lig5a .li2n .li3o .li4t .mag5a5 .mal5o .man5a .mar5ti .me2 .mer3c .me5ter .mis1 .mist5i .mon3e .mo3ro .mu5ta .muta5b .ni4c .od2 .odd5 .of5te .or5ato .or3c .or1d .or3t .os3 .os4tl .oth3 .out3 .ped5al .pe5te .pe5tit .pi4e .pio5n .pi2t .pre3m .ra4c .ran4t .ratio5na .ree2 .re5mit .re
@kostasdizas
kostasdizas / all_git_to_stree
Last active December 22, 2015 00:19
find all git repositories under /Users/ and import them to SourceTree
for folder in $(sudo find /Users -name ".git" -type d | sed 's#\(.*\)/.*#\1#' | sort -u); do
stree $folder;
done
@kostasdizas
kostasdizas / create_git.sh
Last active August 29, 2015 14:03 — forked from anonymous/create.sh
Script for creating an auto updating git repo on a remote server
#!/bin/sh
#
# source: http://stackoverflow.com/questions/279169/deploy-a-project-using-git-push
name="new_project"
mkdir $name
cd $name
git init
git config receive.denyCurrentBranch ignore
curl https://gist.githubusercontent.com/kostasdizas/f76dad08cc3a724b0971/raw/344a590af350b997db3819fa21426dfe8bc140f4/post-update > .git/hooks/post-update
@kostasdizas
kostasdizas / ass1-test.py
Last active August 29, 2015 14:09
CE151 Assignment Testing
import unittest
from unittest.mock import patch
from io import StringIO
import ass1
def ex_run(func, inputs):
print("-" * 50)
print("running: {0} with inputs {1}".format(func.__name__, ", ".join(inputs)))
@kostasdizas
kostasdizas / move_and_symlink.sh
Created August 31, 2015 21:36
Quickly copy a file or folder elsewhere and replace it with a symlink pointing to its new location
@kostasdizas
kostasdizas / led_control.sh
Last active September 7, 2015 13:59
Control the LEDs on a Raspberry Pi
#! /bin/bash
# led_control [on|off] : Turn the LEDs on or off
function display_usage() {
echo "Control the Raspberry Pi leds"
echo -e "\nUsage:\n$0 [on|off]\n"
exit 1
}
[ $# -eq 0 ] && display_usage
@kostasdizas
kostasdizas / comparechecksum.sh
Created September 6, 2015 21:13
Quickly calculate a checksum for a file and compare with input
#!/bin/bash
# compare calculated from file and input checksums for any hash function
if [ $# -lt 3 ] ; then
echo 'usage -- comparechecksum hashfunction filename checksum'
exit 1
fi
[ $($1 $2 | cut -f 1 -d " ") == $3 ] && echo "OK: All good" || echo "NOT OK: File does not match given checksum"