Skip to content

Instantly share code, notes, and snippets.

View bencentra's full-sized avatar

Ben Centra bencentra

View GitHub Profile
@bencentra
bencentra / loose_cannon.py
Last active December 17, 2015 17:39
A short python script for XChat that will automatically reply for you when a user is kicked from the channel.
# Import xchat module
import xchat
# Required module information
__module_name__ = "loose cannon"
__module_version__ = "1.0"
__module_description__ = "Annoy the ops, namely agargiulo"
# Define the callback method for our hook
def loose_cannon_cb(word, word_eol, userdata):
@bencentra
bencentra / spinner.html
Last active January 7, 2023 12:58
A game show/board game style spinner, made with SVG and JavaScript. Add some data to the "Slice" objects and make something useful out of it.
<!DOCTYPE HTML>
<html>
<head>
<title>SVG Spinner</title>
<style type="text/css">
* {
font-family: Arial, sans-serif;
}
#wrapper {
width: 400px;
@bencentra
bencentra / xss_whitelist.php
Created August 17, 2013 01:47
A basic whitelist to prevent XSS.
<?php
function xss_whitelist($input, $limit = null, $offset = 0)
{
// Force input to be a string0
$x = (string) $input;
// Allow alphanumeric characters, whitespace, and specific characters
$x = preg_replace("/[^a-zA-Z0-9 -:,.!?\/|]/", "",$x);
// Limit characters
@bencentra
bencentra / canvas.html
Created February 3, 2014 15:19
Messing around with the HTML5 canvas
<!DOCTYPE HTML>
<html>
<head>
<title>Canvas! Yeah!</title>
<style type="text/css">
* {
font-family: Calibri, Arial, sans-serif;
}
.center {
@bencentra
bencentra / db_utils.php
Last active January 16, 2017 22:22
A bunch of database functions for prepared statements with PDO. Assumes a global $pdo object created in separate 'dbInfo.inc' file.
<?php
// Include the database connection info
require_once("path/to/dbInfo.inc");
/*
* Database methods
*/
function db_select($sql, $data)
{
@bencentra
bencentra / template.html
Last active August 29, 2015 14:00
Template webpage with Boostrap, jQuery, and AngularJS what for the quickly starting of webapps.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<title>Page Title</title>
@bencentra
bencentra / dbInfo.inc
Last active August 29, 2015 14:03
Sample file for storing database credentials and initializing a global PDO object for database operations
<?php
$dbName = ""; // Name of the database to use
$dbUser = ""; // Username of the database user
$dbPass = ""; // Password of the database user
$dbHost = ""; // Host of the database
try {
// Create a global PDO object
$pdo = new PDO(
@bencentra
bencentra / esignature.html
Last active January 30, 2023 14:13
Example of using HTML5 canvas with both mouse and (single) touch input
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<title>E-Signature</title>
@bencentra
bencentra / DatabaseUtils.php
Last active February 14, 2022 14:45
Revised version of db_utils.php, refactored as a PHP class.
<?php
/*
* DatabaseUtils.php - A class of simple database utilities.
*
* Performs CRUD operations using PDO (MySQL) prepared statements.
*
* Author: bencentra (https://gist.github.com/bencentra/92228e1f4139436c4153)
*/
@bencentra
bencentra / getRequestParam.js
Last active August 29, 2015 14:14
Memoized function for getting request parameters from the URL
var getRequestParam = (function(window) {
var params = [], keys = [], values = [];
return function(param) {
var index = -1, pair;
if (params.length === 0) {
params = window.location.href.split("?");
if (params.length === 1) return false;
params = params[1].split("&");
params.forEach(function(p) {
pair = p.split("=");