Skip to content

Instantly share code, notes, and snippets.

@eric1234
eric1234 / README.md
Last active March 27, 2024 07:15
Protect page with simple password

Purpose

Unauthorized access to a PHP page prompts the user for a password. Once the password is entered the original page will show.

Features

  • The access is recorded in the session so it only needs to be
@eric1234
eric1234 / README.md
Last active March 26, 2024 06:17
Environment-based configuration for PHP

Purpose

Somewhat like dotenv but for PHP.

The goals is to remove all config scattered about in files and have one authoritative source for that config info.

Usage

@eric1234
eric1234 / README.md
Last active March 26, 2024 06:16
A database lightweight wrapper to PDO. Reduces the complexities of it's object-oriented interface to a simple functional interface more in the spirit of the original PHP mysql library.

Purpose

The original PHP mysql library was fairly quick to code due to it's simple functional interface. But there were some rough edges. Also it is now deprecated and most developers are moving to PDO since it is more database independent.

Unfortuantly PDO is overly complicated. This is mostly due to PHP's poor object system and the PDO developers desire to make the system object-oriented.

@eric1234
eric1234 / README.md
Last active March 22, 2024 12:54
Generic Ruby Proxy Module

Purpose

A generic proxy module.

Since it's a module it can be mixed into any class. This differs from Ruby's Delegator class which require the inheritance chain to include the Delegator module. Since it implements it's magic via method_missing, it will only proxy the method if the method doesn't exist on the base class or any of it's parent classes.

Example

@eric1234
eric1234 / composed_model.rb
Last active October 11, 2023 19:38
composed model example
concern :ComposedModel do
include ActiveModel::Model
def valid?
objects.all?(&:valid?) && super
end
def save!
raise ActiveRecord::RecordInvalid, self unless valid?
transaction { objects.each &:save! }
@eric1234
eric1234 / README.md
Last active May 20, 2023 15:25
A better way of doing layouts in PHP

Usage

Creating a Layout File

Create a file called layout.php. Where you want the content to appear add <?php echo $content ?>. Here is an example:

@eric1234
eric1234 / git-hub-fork-network.rb
Created September 14, 2009 18:33
Will list all forks related to a project on GitHub.
#!/usr/bin/env ruby
# Provides a way to list forks on github for a project.
#
# git-hub-fork-network user project
require 'rubygems'
require 'octopi'
module Octopi
class Repository < Base
@eric1234
eric1234 / fm.php
Created October 19, 2010 21:38
Very simple file manager
<?php
/*** A stupid simple PHP-based file manager ***/
// Were to put the files. Assume the "fm" directory where this script
// Is located but you can change it to anything you want.
$storage_dir = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'fm'));
// Set to the name of the file that is the header and footer of the HTML
$header = null;
$footer = null;
@eric1234
eric1234 / index.js
Last active April 15, 2022 16:02
PouchDB Rollup Conflict
import PouchDB from 'pouchdb-browser'
import MemoryAdapterPlugin from 'pouchdb-adapter-memory'
PouchDB.plugin(MemoryAdapterPlugin)
@eric1234
eric1234 / README.md
Last active April 12, 2022 13:18
Easy HTTP Auth in PHP

Usage

At the top of the page you want to secure:

auth('admin', 'passw0rd')

Now when someone visits that page they must enter admin/passw0rd to see the page.