Skip to content

Instantly share code, notes, and snippets.

View cronoh's full-sized avatar

Andrew Steele cronoh

View GitHub Profile
@cronoh
cronoh / gist:8380085
Created January 12, 2014 02:46
Attempting to learn proper code separation in Laravel
/* In My Controller */
public function processRegister() {
$validator = Validator::make(Input::all(), User::$baseValidationRules); // Create validation
if ($validator->fails()) {
Session::flashInput(Input::all()); // Save the user input for one request
return Redirect::to('register')->withErrors($validator); // Send them back to registration with validation errors
}
if ((new User)->createFromInput()) {
Session::flash('successMessage', 'Your account has been created! You can log in now');
@cronoh
cronoh / gist:8384299
Created January 12, 2014 12:58
I get this error when using Laravel 4/Eloquent: I don't see this requirement anywhere in the docs? Undefined property: Setting::$attributes /­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php:2204
class Setting extends Eloquent {
protected $guarded = array('id');
protected $fillable = array('name', 'value');
public static function setValue($name, $value) {
$setting = self::firstOrCreate(['name' => $name]); // Error happens here
$setting->value = $value;
return $setting->save() ? $setting : false;
}
}
/* Setting Model */
class Setting extends Eloquent {
public function setValue($name, $value) {
$setting = $this->firstOrCreate(array('name' => $name));
$setting->value = $value;
return $setting->save() ? $setting : false;
}
}
/* Controller */
/**
* Get a unique mailbox address
* @return string
*/
public function getUniqueAddress() {
do {
$address = Mailbox::createRandomAddress();
$existingAddress = Mailbox::where('address', 'LIKE', $address)->first();
} while ($existingAddress);
return $address;
@cronoh
cronoh / gist:9004782
Created February 14, 2014 16:58
Laravel MultiSelect Custom Validation Rules: multi_exists, multi_max, and multi_min
use Illuminate\Validation\Validator;
class CustomValidationRules extends Validator
{
protected function validateMultiExists($attribute, $value, $parameters)
{
if (!is_array($value)) return false;
foreach ($value as $submitValue)
{
@cronoh
cronoh / gist:a52fcc41936c217d3a19
Created June 18, 2015 01:05
AngularJS Authentication Interceptor
angular.module('myApp', [])
.config(function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
$httpProvider.interceptors.push('authInterceptor');
})
.factory('authInterceptor', function ($rootScope, $q, $cookieStore, $location, localStorageService) {
return {
// Add authorization token to headers
request: function (config) {
config.headers = config.headers || {};
angular.module('myApp', [])
.run(function ($rootScope, $location, Auth) {
//Redirect to login if route requires auth and you're not logged in
$rootScope.$on('$stateChangeStart', function (event, next) {
Auth.isLoggedIn().then(function(loggedIn) {
if (next.authenticate && !loggedIn) {
$location.path('/login');
}
});
});
exports.show = function(req, res) {
var query = {};
if (typeof req.query.name !== 'undefined') {
query.name = req.params.id;
} else {
query._id = req.params.id;
}
Channel.findOne(query, function (err, channel) {
if(err) { return handleError(res, err); }
freelance
remote
http://hnhiring.me/
https://github.com/lukasz-madon/awesome-remote-job/
http://www.lancelist.com/
https://gun.io/dash/
http://www.10xmanagement.com/
https://theworkmob.com/
http://workingnotworking.com
https://authenticjobs.com
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;