Skip to content

Instantly share code, notes, and snippets.

View AstDerek's full-sized avatar

Ast Derek AstDerek

View GitHub Profile
@AstDerek
AstDerek / quicksort.cpp
Created October 2, 2012 19:23
Implementación simple de Quick Sort
#include <iostream>
using namespace std;
void intercambiar_int (int *a, int *b) {
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
@AstDerek
AstDerek / order-methods.php
Created October 2, 2012 19:24
Métodos de ordenación
<?php
set_time_limit(0);
ini_set('memory_limit','128M');
function burbuja ($v,&$metodo) {
$tmp = $v[0];
$N = count($v);
$metodo['burbuja']['tiempo'] = microtime(true);
@AstDerek
AstDerek / combinaciones-debug.cpp
Created October 3, 2012 14:17
Combinaciones mostradas paso a paso
#include <iostream>
#include <stdlib.h>
using namespace std;
// copiar un array en otro
// si *copia es NULL, se aloja memoria para guardarlo
double *copiar (double *array, double *copia, unsigned long longitud) {
if (!copia) {
copia = (double *)calloc(longitud,sizeof(double));
@AstDerek
AstDerek / combinaciones.cpp
Created October 3, 2012 14:22
Combinaciones finales
#include <iostream>
#include <stdlib.h>
using namespace std;
// copiar un array en otro
// si *copia es NULL, se aloja memoria para guardarlo
double *copiar (double *array, double *copia, unsigned long longitud) {
if (!copia) {
copia = (double *)calloc(longitud,sizeof(double));
@AstDerek
AstDerek / final.c
Created November 4, 2012 19:17
Editor de texto simple
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*#define TECLA_ARRIBA 72*/
/*#define TECLA_ABAJO 80*/
/* El programa fue probado a través de SSH, no funcionan las flechas */
#define TECLA_ARRIBA 'r'
#define TECLA_ABAJO 'b'
@AstDerek
AstDerek / agregar_nueva_linea.c
Created November 8, 2012 08:10
Agregar nueva línea
void agregar_nueva_linea () {
segmento *ultimo_segmento;
char linea[ANCHO_LINEA];
int continuar = 1;
while (continuar) {
fgets(linea,ANCHO_LINEA,stdin)
/* Si hay una nueva línea, es que acabamos de procesar el texto */
if (linea[strlen(linea) - 1] == '\n') {
@AstDerek
AstDerek / event.rb
Created January 8, 2013 03:58
Simple Rails app compatible with DHTMLX Scheduler http://www.dhtmlx.com/docs/products/dhtmlxScheduler/index.shtml
class Event < ActiveRecord::Base
attr_accessible :_timed, :details, :end_date, :start_date, :text
# From http://www.dhtmlx.com/docs/products/dhtmlxScheduler/xml/events.xml
def to_xml (options = {})
options[:indent] ||= 2
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
xml.instruct! unless options[:skip_instruct]
xml.event(:id => id, :timed => _timed) do
xml.text text
class Album < ActiveRecord::Base
has_many :images
belongs_to :gallery, :polymorphic => true
attr_accessible :title
end
@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(){};
<?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