Skip to content

Instantly share code, notes, and snippets.

View rmrhz's full-sized avatar
💻
dustin n' hustlin' n' d' base

rm "rhz" rmrhz

💻
dustin n' hustlin' n' d' base
View GitHub Profile
@rmrhz
rmrhz / dynamic.php
Last active August 29, 2015 14:04
Enables dynamic domain routing in Laravel > 4.1.*
<?php
if( ! preg_match('/^'.Config::get('app.domain').'$/', Request::server('HTTP_HOST')) ) {
// Setup the host
$host = Request::server('HTTP_HOST');
$domain = preg_replace('/^www\./', '', $host);
// Setup domain configuration
Config::set('app.url', 'http://' . $host);
@rmrhz
rmrhz / ioc.php
Created August 13, 2014 13:14
Simple IoC / DI Container
<?php
class foo {
protected $registry = [];
public function __construct()
{
$that = $this;
$containers = [
@rmrhz
rmrhz / config_installer.py
Created October 21, 2014 06:27
Just a random configuration install
import commands
import platform
import os.path
# Check distribution
distro = platform.linux_distribution()[0]
# Find out distribution we're on (version and architecture wouldn't matter)
if distro == 'Ubuntu':
httpServices = ['apache2', 'nginx']
@rmrhz
rmrhz / AuthExtensionComponent.php
Last active August 29, 2015 14:08
Authenticates the user, saves only the user id in the session cache, return the authenticated user's attributes with its model.
<?php
App::uses('AuthComponent', 'Controller/Component');
class AuthExtensionComponent extends AuthComponent {
// AuthExtension Notes
// This will override default routines of AuthComponent
// `$this->Auth->user()` as per the default will return as an array
// `$this->user()` is modified to only contain `Account.id`
@rmrhz
rmrhz / .vimrc
Last active August 29, 2015 14:08
Muh settings
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'bling/vim-airline'
Plugin 'kien/ctrlp.vim'
@rmrhz
rmrhz / spammer.rb
Created December 17, 2014 09:22
Spams a certain URL with an 'effin parameter
require 'curb'
x = 500
i = 0
while x > i do
# Creates a random string
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
string = (0...10).map { o[rand(o.length)] }.join
@rmrhz
rmrhz / dl.rb
Created December 30, 2014 08:49
Simple HTTPAuth based Ruby downloader
require 'open-uri'
urls = [
'http://example.com/image.jpg',
'http://example.com/image2.jpg'
]
urls.each do |url|
open(url, :http_basic_authentication => [user, pass]) {|f|
File.open(File.basename(url),"wb") do |file|
@rmrhz
rmrhz / nginx.sh
Created January 10, 2015 19:21
Install latest Nginx on CentOs 6.*
# Install Nginx
echo "Installing Nginx.."
sleep 2
cat <<EOF > /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/\$basearch/
gpgcheck=0
enabled=1
EOF
@rmrhz
rmrhz / Repository.php
Created October 12, 2015 16:08
An impractical use for mass assignments in Laravel.
<?php
class Repository
{
/**
* Mass assignment based on fillable, hidden, and guarded attributes
*
* @param obj $model
* @param arr $insertArray
@rmrhz
rmrhz / Controller.php
Created November 30, 2015 22:08
Automatically return a JSON response when `return` is invoked
<?php
use Phalcon\Mvc\View;
class Controller extends \Phalcon\Mvc\Controller
{
/**
*
* @return \Phalcon\Http\Response
*/