Skip to content

Instantly share code, notes, and snippets.

View AstDerek's full-sized avatar

Ast Derek AstDerek

View GitHub Profile
<style>
iframe { border:none;border-bottom:1px solid #ccc;width:100%;height:250px; }
body, * { font-family:Consolas,"Lucida Console","Lucida Typewritter","Courier New",Courier,monospace; }
</style>
<?php
class FOO {
public $f;
}
(function($){
function time_to_hms (time) {
var amounts = {
hours: 60*60,
minutes: 60,
seconds: 1
},
hms = [],
unit = '',
amount = '',
<?php
// Example on how to handle JSON responses
if ($session->logged_in()) {
$json_response = array(
'error' => FALSE,
'user_id' => $session->user_id()
);
}
else {
<?php
// Query with no Active Record
$query = "SELECT questions.* FROM assessments LEFT JOIN questions ON assessments.id=questions.assessment_id WHERE assessments.id=4";
// Query with ORM (Idiorm)
ORM::for_table('assessments')
->select('questions.*')
->join('questions',array('assessments.id','=','questions.assessment_id'))
->where('assessments.id',4)
<?php
// No model, but ORM
if ($assessment->startdate > $now || $assessment->enddate < $now)) {
// Assessment is expired
}
// Model and ORM, example
if ($assessment->expired_at_date($now)) {
// Assessment is expired
@AstDerek
AstDerek / orm-comparison.php
Created February 17, 2013 04:00
Comparison between original code, and ORM code
<?php
// Without ORM
$forum_id = 0;
$query = "select id from imas_forums where courseid = ".$_GET['courseid'];
$result = mysql_query($query) or die("Query failed: ".mysql_error());
$foro = mysql_fetch_row($result);
if(count($foro)>0)
$forum_id = $foro[0];
<?php
// Comenzar la sesión
session_start();
// revisar que el array exista
if (!is_array($_SESSION['comentarios'])) {
$_SESSION['comentarios'] = array();
}
$dato = $_POST['TxtboxCmtar'];
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query("CREATE TABLE IF NOT EXISTS comentarios (id INT(11) NOT NULL AUTO_INCREMENT, comment TEXT, fecha TIMESTAMP, PRIMARY KEY(id))");
$dato = $_POST['TxtboxCmtar'];
if (validar_usuario() && es_texto($dato)) { // En PHP, para comprobar una cadena, generalmente esa cadena es enviada a una función, como argumento
@AstDerek
AstDerek / collection.php
Last active December 11, 2015 04:38
Wrapping class for arrays. Simulates ruby closure usage.
<?php
class Collection extends ArrayIterator {
public function map ($closure=FALSE) {
$copy = $this->getArrayCopy();
if (is_string($closure)) {
$copy = array_map(function($value)use($closure){
$function = function(){};
class Album < ActiveRecord::Base
has_many :images
belongs_to :gallery, :polymorphic => true
attr_accessible :title
end