Skip to content

Instantly share code, notes, and snippets.

View milosdakic's full-sized avatar

Milos Dakic milosdakic

View GitHub Profile
@iben12
iben12 / 1_Laravel_state-machine.md
Last active August 12, 2023 08:36
Laravel: State-machine on Eloquent Model

Implementing State Machine On Eloquent Model*

* Update (12.09.2017): I have improved the trait so that it can be used with objects other than Eloquent Models.

Some days ago I came across a task where I needed to implement managable state for an Eloquent model. This is a common task, actually there is a mathematical model called "Finite-state Machine". The concept is that the state machine (SM) "can be in exactly one of the finite number of states at any given time". Also changing from one state to another (called transition) depends on fulfilling the conditions defined by its configuration.

Practically this means you define each state that the SM can be in and the possible transitions. To define a transition you set the states on which the transition can be applied (initial conditions) and the only state in which the SM should be after the transition.

That's the theory, let's get to the work.

@steveneaston
steveneaston / VerifyShopifyWebhook.php
Created September 15, 2015 17:21
Verify a Shopify hook signature using Laravel Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class VerifyShopifyWebhook
{
/**
* Handle an incoming request.
@adamwathan
adamwathan / import-reference.md
Last active December 5, 2016 06:58
Importing class mixins by reference

This is the workflow I really love with Less that's missing in Sass. Killer way to use a library like Bootstrap without coupling any of your markup to Bootstrap itself.

Import a bunch of vendor styles by reference only, mix in the classes you want to keep into your own aliases, no vendor class names end up in your compiled CSS.

Sass doesn't support reference import or the ability to mixin a class, only a mixin.

// Vendor less
.btn {
 // a bunch
@alanhamlett
alanhamlett / responsive.less
Last active September 30, 2020 18:19
Responsive helper classes for Bootstrap style margins, padding, aligning, and displaying per screen size
/* responsive.less
* ~~~~~~~~~~~~~~~
*
* Responsive helper classes for Bootstrap style margins, padding, aligning, and displaying per screen size.
* Works along with Bootstrap3.
*/
//== Media queries breakpoints from Bootstrap3
// Extra small screen / phone
@xmlking
xmlking / Enum.es6.js
Last active June 25, 2019 18:09
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;
@staltz
staltz / introrx.md
Last active July 22, 2024 09:31
The introduction to Reactive Programming you've been missing
@paulinm
paulinm / gauge.js
Last active August 21, 2019 07:30 — forked from tomerd/gauge.js
A Google-style Gauge Implemented using D3 with Optional Min, Max, and Running Average Tracking
function Gauge(placeholderName, configuration)
{
this.placeholderName = placeholderName;
var minValue = null;
var maxValue = null;
var avgValue = null;
var avgCounter = 0;
var self = this; // for internal d3 functions
@juliocesar
juliocesar / gist:4108378
Created November 19, 2012 00:45
Backbone.Model in localStorage
# Storing a Backbone.Model in localStorage
# ========================================
#
# You can then use localStorage as a collection. For an usage example, see
# https://github.com/juliocesar/factory/blob/master/coffeescripts/factory.coffee#L149
# This largely Just Worked™ for my needs. YMMV!
class MyModel extends Backbone.Model
sync: (method, model, rest...) ->
@webfella
webfella / bootyshaker.coffee
Created August 21, 2012 12:14
Wobble function
# small function to use with jquery to shake an element.
shakeThatBooty = (e, amount, counter) ->
speed = 50
if (counter == 0) then return
e.animate
right: amount
, speed, ->
e.animate
right: -amount
@bruth
bruth / gist:2865951
Last active November 19, 2017 20:11
Backbone Sync Queue
# Reference Backbone ajax function
_ajax = Backbone.ajax
requestQueue = []
requestPending = false
sendRequest = (options, promise, trigger=true) ->
options = _.clone options
if trigger
requestPending = true