Skip to content

Instantly share code, notes, and snippets.

View callumacrae's full-sized avatar

Callum Macrae callumacrae

View GitHub Profile
<?php
class Hash extends Plugin
{
public function pbkdf2($input, $s = null, $c = null, $kl = null, $a = null)
{
$s = is_null($s) ? $this->config['s'] : $this->pbkdf2($s);
$c = is_null($c) ? $this->config['c'] : $c;
$kl = is_null($kl) ? $this->config['kl'] : $kl;
$a = is_null($a) ? $this->config['alg'] : $a;
@callumacrae
callumacrae / auth.php
Created February 26, 2011 18:31
The plugin
<?php
namespace lynx\Plugins;
class Auth extends Plugin
{
public function login($user, $pass, $remember)
{
$user = $this->db->select(array(
'FROM' => $this->config['table'],
<?php
class URL
{
public function auto($string, $type = 'both', $attr = false, $echo = false)
{
if ($type == 'both' || $type == 'url')
{
$regex = '/(?<anchor><a(?:\s+(?<attr>(?:\S+?=(?:(?:\'.*?\')|(?:".*?")\s*))+))?>(?<text>.*?)<\/a\s*>)|(?<!>)(?<url>(?<proto>https?:\/{2})(?<domain>[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,3})(?<path>\/\S*)?)/i';
return preg_replace_callback($regex, function($matches)
{
<?php
namespace Framework\Controllers;
//include the model
require_once(ROOT . '/models/user.php');
use \Framework\Models\UserModel as UserModel;
class User
{
<?php
// Check if the cookie is already set, otherwise set some default styling options
// Also, we need to unserialize the value of the cookie as we are working with arrays
$style = !empty($_COOKIE['style']) ? unserialize($_COOKIE['style']) : null;
// First check if the keys in the arrays are empty, then check if it starts with #
$body_background_color = !empty($style['body_background_color']) ? (strpos($style['body_background_color'],"#") !== 0 ? "#". $style['body_background_color'] : $style['body_background_color']) : "#fff";
$body_text_color = !empty($style['body_text_color']) ? (strpos($style['body_text_color'],"#") !== 0 ? "#". $style['body_text_color'] : $style['body_text_color']) : "#000";
$body_text_size = !empty($style['body_text_size']) ? $style['body_text_size'] : 12;
@callumacrae
callumacrae / bot.js
Created May 28, 2011 12:19
Node.js IRC bot
var net = require('net'),
irc = {}, config;
config = {
user: {
nick: '',
user: '',
real: '',
pass: ''
},
var http = require('http'),
events = require('events');
function Twitter(options, track)
{
var user, pass, authstring,
__self, req, emitter;
__self = this;
emitter = events.EventEmitter.call(this);
authstring = (new Buffer(options.user + ':' + options.pass, 'ascii')).toString('base64');
<?php
set_time_limit(0);
$address = '192.168.2.102';
$port = 9000;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Could not bind to address');
socket_listen($sock);
var storage = {};
if (window.localStorage)
{
storage.get = function(name)
{
if (window.localStorage[name] === undefined)
{
return undefined;
}
return JSON.parse(window.localStorage[name]);
@callumacrae
callumacrae / jquery.form.js
Created July 17, 2011 12:41
jquery.form.js
/*!
* jQuery Form Plugin 2.83 (11-JUL-2011)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
/**
* ajaxSubmit() provides a mechanism for immediately submitting
* an HTML form using AJAX.