Skip to content

Instantly share code, notes, and snippets.

View cyberfly's full-sized avatar

Muhammad Fathur Rahman cyberfly

View GitHub Profile
@ghinda
ghinda / object-to-form-data.js
Last active May 13, 2025 05:55
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@jwalton512
jwalton512 / Api\Admin\TestCase.php
Created August 9, 2015 08:46
Api Testing With Laravel 5.1 (jwt-auth)
<?php
namespace Tests\Api;
use App\User;
use Tests\TestCase as BaseTestCase;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
class TestCase extends BaseTestCase
{
@nasrulhazim
nasrulhazim / readme.md
Last active August 30, 2021 01:29
Using Yajra Datatables with Laravel 5.3

Installation

composer require yajra/laravel-datatables-oracle:~6.0

Open up config/app.php and add the following in providers key:

Yajra\Datatables\DatatablesServiceProvider::class,
@bobbybouwmann
bobbybouwmann / User.php
Last active May 31, 2024 03:04
Laravel Absolute vs Relative Dates with Carbon
<?php
namespace App;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
@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.

@cyberfly
cyberfly / gist:5f1f95981bfc11a7bcb5343ed03ccfff
Last active April 18, 2017 04:44
NPM, Bower and Grunt Command when working with AngularJS project
//things to do after clone angular project
npm install
bower install
grunt wiredep
grunt server
//check version of all installed bower packages
bower list --json=0 --offline
//update angular version using bower
@cyberfly
cyberfly / new_gist_file_0
Created May 9, 2017 07:20
GIT untracked changes to local config file
You could update your index:
cd /root/folder/of/your/repo
git update-index --assume-unchanged nbproject/project.properties
and make sure it never shows as "updated" in your current repo.
That means it won't ever been pushed, but it is still present in the index.
(and it can be modified at will in your local working tree).
@cyberfly
cyberfly / gittips.txt
Created May 24, 2017 01:56
How do I resolve git saying “Commit your changes or stash them before you can merge”? https://stackoverflow.com/a/15745424/417899
You can't merge with local modifications. Git protects you from losing potentially important changes.
You have three options.
1. Commit the change using
git commit -m "My message"
2. Stash it.
Stashing acts as a stack, where you can push changes, and you pop them in reverse order.
@NishiGaba
NishiGaba / iterate-over-array.js
Last active November 29, 2023 10:27
8 Methods to Iterate through Array
//8 Methods to Iterate through Array
//forEach (Do Operation for Each Item in the Array)
[1,2,3].forEach(function(item,index) {
console.log('item:',item,'index:',index);
});
//map (Translate/Map all Elements in an Array to Another Set of Values.)
const oneArray = [1,2,3];
const doubledArray = oneArray.map(function(item) {
@cyberfly
cyberfly / CheckRequestPermission.php
Last active November 28, 2017 06:40
Form Request trait for route validation and role permission
<?php namespace App\Traits;
use App\MeetingApprovalCommittee;
use App\Role;
trait CheckRequestPermission {
/**
* Check role permission to form request class to be validated
*