Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Sigmus / FormUtils.php
Created December 14, 2012 13:05
Laravel FormUtils
<?php
class FormUtils {
/**
* Manipulates object using current input.
*
* @param Eloquent $eloquent
* @return Eloquent
*/
@Sigmus
Sigmus / IsPointInPoly.js
Created December 17, 2012 13:42
Asserts if a given point is inside a polygon.
//+
//@ http://jsfromhell.com/math/is-point-in-poly [v1.0]
function isPointInPoly(poly, pt){
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y))
&& (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)
&& (c = !c);
return c;
}
app.get '/jade/*', (req, res) ->
  fs.readFile app.get('views') + "/#{req.params}.jade", 'utf-8', (err, tpl) ->
    res.json err if err
    functionBody = jade.compile(
      tpl, client:true, compileDebug:false
    ).toString().replace 'anonymous', ''
    res.set 'Content-Type', 'application/javascript'
    res.send """
 define([], function(){
@Sigmus
Sigmus / gist:4331921
Created December 18, 2012 20:59
Laravel: modelo temporário
<?php
// Na tabela existe uma coluna booleano "temp" que é "true" por padrão.
Route::get('/admin/edicao/create', function() {
return Redirect::to('/admin/edicao/' . Edicao::createTemp()->id);
});
// E no modelo tem os seguintes métodos:
public static function createTemp() {
@Sigmus
Sigmus / Permission.php
Last active December 11, 2015 00:59
Refactored Permission class.
<?php
class Permission {
public static function ask()
{
return static::action('Question');
}
public static function answer()
@Sigmus
Sigmus / Permission.php
Created January 14, 2013 13:54
Permission
<?php
class Permission
{
public static function action($action)
{
return self::$action();
}
private static function ask()
@Sigmus
Sigmus / generic_m2m.php
Created January 14, 2013 19:58
Generic attach m2m relationship service.
<?php
// Generic attach m2m relationship service.
Route::post('/admin/attach', function()
{
$input = Input::get();
$parent = $input['parent']['name']::find($input['parent']['id']);
$child = $input['child']['name']::find($input['child']['id']);
define(['modal/standard', 'belongs'], function(Modal, Belongs) {
return function(params) {
var modal = Modal(params).hijack();
params.after = function(){
modal.close();
};
define(function(){
return function(params){
return {
init: function() {
var that = this;
$('a.share').on('click', function(e){
e.preventDefault();
define(['modal/standard', 'belongs'], function(Modal, Belongs) {
return function(params) {
params.onCreate = params.onCreate || function(json, child) {
if (json.status !== 1) {
alert('Ocorreu um erro!');
return;
}