Skip to content

Instantly share code, notes, and snippets.

View Rican7's full-sized avatar
😮
My dotfiles just keep getting better... and its been OVER 10 YEARS NOW! ⌚😮🤯

Trevor N. Suarez Rican7

😮
My dotfiles just keep getting better... and its been OVER 10 YEARS NOW! ⌚😮🤯
View GitHub Profile
@Rican7
Rican7 / Singleton.php
Created November 9, 2012 05:51
PHP 5.3+ Singleton Pattern Class (with aliases for ease of use)
<?php
// PHP 5.3+ Singleton Pattern
abstract class Singleton {
// Constructor
private function __construct() {
// Do nothing
}
@Rican7
Rican7 / changeIsColsToBool.sql
Created November 26, 2012 20:38
MySQL: Change all columns starting with "is_" of a table from "int"'s to "boolean"s
DROP PROCEDURE IF EXISTS changeIsColsToBool;
DELIMITER //
CREATE PROCEDURE changeIsColsToBool(
myschema VARCHAR(255),
defaultVal BOOL
)
BEGIN
DECLARE colname VARCHAR(255) default 'is\_%';
DECLARE mytable VARCHAR(255);
DECLARE col VARCHAR(255);
@Rican7
Rican7 / changeIntToTimestamps.sql
Created November 26, 2012 20:40
MySQL: Change all given columns of a table from "int"'s to "timestamps"
DROP PROCEDURE IF EXISTS changeIntToTimestamps;
DELIMITER //
CREATE PROCEDURE changeIntToTimestamps(
myschema VARCHAR(255),
colname VARCHAR(255),
autoUpdate BOOL
)
BEGIN
DECLARE mytable VARCHAR(255);
DECLARE col VARCHAR(255);
@Rican7
Rican7 / url-rewriting.md
Created December 3, 2012 00:16
URL Rewriting

URL-rewriting for klein PHP router

Why rewrite URLs? Check Wikipedia

Apache

Make sure AllowOverride is on for your directory, or put in httpd.conf

# Apache (.htaccess or httpd.conf)

RewriteEngine On

@Rican7
Rican7 / addTestData.sql
Created April 10, 2013 17:44
Easily add test data via a procedure loop. :)
DROP PROCEDURE IF EXISTS addTestData;
delimiter //
CREATE PROCEDURE addTestData(cnt INT)
BEGIN
SET @x = 0;
REPEAT
SET @x = @x + 1;
INSERT INTO `TABLE_NAME_HERE` (`name`) VALUES ( CONCAT( 'test_data_', @x) );
%s/^\(\s\+\)\$this->assertOutputSame(\n\(.\{-}\)\n\(.\{-}\)function (.*) {\n\(.\{-}\)\$this->klein_app->dispatch(\(\(\n\?.*\)\)\n\(.*\));\n.*}\n\(.*\));/\1\$this->assertSame(\r\2\r\3\$this->dispatchAndReturnOutput(\5\r\3)\r\1);/g
@Rican7
Rican7 / codecademy-battleship.py
Created July 6, 2013 21:47
Just a very basic (and pretty ghetto) procedural-style Battleship game written in Python, from the Codecademy Python lesson. :)
from random import randint
board = []
for x in range(5):
board.append(["O"] * 5)
def print_board(board):
# Print a new-line
#!/usr/bin/env php
<?php
/**
* JSON/BSON encoding and decoding benchmark
*
* Now with native serializing!
*
* @copyright 2013 Trevor N Suarez
* @link http://blennd.com/
* @author Trevor Suarez <rican7@gmail.com>
<?php
class Dog {
public function paramSmart($val = null) {
if (null !== $val) {
return $this->paramSmart = $val;
}
return $this->paramSmart;
}
@Rican7
Rican7 / dart-version-of-codecademy-battleship.dart
Last active December 28, 2015 09:39
A Dart(lang) translation of an old Codecademy project originally used to learn Python. PS: Dart's pretty boss. Original Python version: https://gist.github.com/Rican7/5941418
import "dart:math";
import "dart:io";
// Declare our game variables
List board;
Random randomizer;
int numOfRows = 5;
int numOfCols = 5;
int shipRow;
int shipCol;