Skip to content

Instantly share code, notes, and snippets.

@aaronsama
aaronsama / README.md
Last active June 15, 2016 17:03
Star rating
@boneskull
boneskull / README.md
Last active June 24, 2023 13:42
syntax highlighting for Vagrantfile in non-RubyMine JetBrains IDEs
  1. Add this file to /path/to/prefs/filetypes/
  2. Restart IDE

This page will help you find the correct directory.

@themsaid
themsaid / HasEnums.php
Last active August 29, 2020 23:23
PHP Enumerated Type
trait HasEnums
{
/**
* The array of enumerators of a given group.
*
* @param null|string $group
* @return array
*/
static function enums($group = null)
{

UsedByTeams Model Trait For Laravel Spark

Automatically limit your models to the current team

So you're using spark, and you have teams enabled. You start creating models and want to have them be team specific. Instead of writing, Model::where('team_id', auth()->user()->currentTeam->id)->get(); use this trait to add that behind the scenes so that every time you call on your model, it's assumed that you mean for the current team.

This assumes that the model has a team_id, while it adds a scope of where team_id = currentTeam->id.

Note: Implicit Route Model Binding in 5.2, auth session doesn't exist at the point of this trait causing issue. fixed in 5.3

@pranid
pranid / Amortization.php
Last active May 1, 2024 15:05
Amortization Schedule Example -- PHP Version
<?php
/**
* AMORTIZATION CALCULATOR
* @author PRANEETH NIDARSHAN
* @version V1.0
*/
class Amortization
{
private $loan_amount;
private $term_years;
@mikemand
mikemand / README.md
Last active August 25, 2016 16:38
MySQL IP Address octets from binary field

From: http://dev.mysql.com/doc/refman/5.7/en/bit-functions.html#c9386

Posted by Neil Davis on April 3, 2008
Revised by Phillip Temple on September 11, 2008

If you store your ip addresses as a 32 bit unsigned integer representation instead of strings(using INET_ATON()), you can use bitwise operators to pull the octets for grouping and sorting when you need to retrieve them:

select 
ipAddress, (ipAddress >> 24) as firstOctet,
  • Modify: composer.json to use php 5.6.4 and laravel 5.3.*

  • Modify: config/app.php

  • Modify: app/Http/Kernel.php

    • replace can line with:
  • 'can' =&gt; \Illuminate\Auth\Middleware\Authorize::class,

@avafloww
avafloww / PhpJava.java
Last active October 16, 2022 18:50
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
var currencyValidator = {
format: function (number) {
return (Math.trunc(number * 1000000000000) / 1000000000000).toFixed(2)
},
parse: function (newString, oldNumber) {
var CleanParse = function (value) {
return { value: value }
}
var CurrencyWarning = function (warning, value) {
return {
@andre-luiz-dos-santos
andre-luiz-dos-santos / trace.coffee
Created January 19, 2017 18:56
A plugin for Vue.JS to help beginners
# Only works on named components
# Vue.use( require('src/plugins/trace') )
# npm install -g coffee-script
# coffee -bc trace.coffee
css = (color = 'black') -> "
background: #{color};
font-weight: bold;
color: white;