Skip to content

Instantly share code, notes, and snippets.

View ZachMoreno's full-sized avatar

Zachariah Moreno ZachMoreno

View GitHub Profile
@ZachMoreno
ZachMoreno / mysql_prep.php
Created December 21, 2011 00:54
MySQL_Prep
<?php
//use this function to clean values going into mysql
function mysql_prep($value)
{
$magic_quotes_active = get_magic_quotes_gpc();//boolean - true if the quotes thing is turned on
$new_enough_php = function_exists("mysql_real_escape_string");//boolean - true if the function exists (php 4.3 or higher)
if($new_enough_php)
{
if($magic_quotes_active)
@ZachMoreno
ZachMoreno / Reduce_Image_Size.php
Created February 21, 2012 07:32
Reduce Image Size
<?php
function reduce_image_size($userfile_name, $userfile_type)
{
//get the file and figure out what type of file it is and some of its attributes
switch ($userfile_type)
{
case "image/pjpeg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/jpeg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/jpg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/gif": $tempbig = imagecreatefromgif(IMG_PATH.$userfile_name); break;
@ZachMoreno
ZachMoreno / square_thumbnail.php
Created February 21, 2012 07:34
Create Square Thumbnails
<?php
function create_square_thumbnails($userfile_name, $userfile_type)
{
//get the file and figure out what type of file it is and some of its attributes
switch ($userfile_type)
{
case "image/pjpeg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/jpeg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/jpg": $tempbig = imagecreatefromjpeg(IMG_PATH.$userfile_name); break;
case "image/gif": $tempbig = imagecreatefromgif(IMG_PATH.$userfile_name); break;
@ZachMoreno
ZachMoreno / pagination.php
Created February 21, 2012 07:35
Pagination
<?php
function pagination ()
{
$per_page = 16;
$pages_query = mysql_query ("SELECT 'file_id' FROM 'imagefiles' LIMIT $star, $per_page");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $page;
@ZachMoreno
ZachMoreno / authenticate_user.php
Created February 21, 2012 07:40
Session Start
<?php
function authenticate_user($login, $password, $key)
{
$val = set_codes();
$query = "select * from users where login='$login' and password = encode('$password', '$key')";
$result = mysql_query ($query);
$row = mysql_fetch_row($result);
if (mysql_num_rows($result) > 0)
{
// IndexedDB
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB,
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction,
dbVersion = 1;
// Create/open database
var request = indexedDB.open("elephantFiles", dbVersion);
request.onsuccess = function (event) {
console.log("Success creating/accessing IndexedDB database");
<!doctype html>
<html ng-app>
<head>
<script src="http://code.angularjs.org/angular-1.0.0rc10.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<div ng-controller="AlbumCtrl">
<ul>
<li ng-repeat="image in images">
<img ng-src="{{image.thumbnail}}" alt="{{image.description}}">
</li>
</ul>
</div>
<input type="text" ng-model="todoText" size="30" placeholder="add new todo here">
function TodoCtrl($scope) {
$scope.todos = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false}];
// Add
$scope.addTodo = function() {
$scope.todos.push({text:$scope.todoText, done:false});
$scope.todoText = '';
};