Skip to content

Instantly share code, notes, and snippets.

View jadjoubran's full-sized avatar
Building learnjavascript.online & react-tutorial.app

Jad Joubran jadjoubran

Building learnjavascript.online & react-tutorial.app
View GitHub Profile
@jadjoubran
jadjoubran / urlobject.js
Last active December 17, 2015 13:09 — forked from aymanfarhat/urlobject.js
Instead of returning #hash the function will now return 'hash' I don't think that there is any case where the # in the urlObject.hash will be useful
function urlObject(options)
{
default_options = {'url':window.location.href,'unescape':true,'convert_num':true};
if(typeof options !== "object")
options = default_options;
else
{
for(var index in default_options)
{
@jadjoubran
jadjoubran / PostsController.php
Last active August 27, 2016 10:32
Laravel Response Macro - Original PostsController.php
<?php
use App\Post;
class PostsController
{
public function get()
{
try {
//some code
@jadjoubran
jadjoubran / ResponseMacroServiceProvider.php
Created August 27, 2016 10:33
Laravel Response Macros
<?php
class ResponseMacroServiceProvider extends ServiceProvider
{
public function boot()
{
Response::macro('success', function ($data) {
return Response::json([
'errors' => false,
'data' => $data,
@jadjoubran
jadjoubran / PostsController.php
Created August 27, 2016 10:34
Laravel Response Macros - Refactored
<?php
class PostsController
{
public function get()
{
try {
//some code
}catch (Exception $e){
return response()->error($e->getMessage);
@jadjoubran
jadjoubran / API.service.js
Created August 29, 2016 11:11
Angular error interceptors
export class APIService {
constructor(Restangular, ToastService) {
'ngInject';
var headers = {
'Content-Type': 'application/json',
'Accept': 'application/x.laravel.v1+json'
};
return Restangular.withConfig(function(RestangularConfigurer) {
@jadjoubran
jadjoubran / controller.js
Created August 29, 2016 11:12
Angular error interceptors
API.all('products').post({title, price}).then( (response) => {
var user = response.data.user;
});
@jadjoubran
jadjoubran / controller.js
Created August 29, 2016 11:12
Angular error interceptors
API.all('products').post({title, price}).then( (response) => {
var user = response.data.user;
}, (response) => {
//response.status
//response.data
});
@jadjoubran
jadjoubran / config.js
Created August 29, 2016 18:30
Enable production mode in angular
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
@jadjoubran
jadjoubran / app.js
Created May 4, 2017 15:07
Promyfill fetch demo
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
promyfill('fetch' in window, fetchPolyfill).then(() => {
//fetch is available (polyfill is fetched only if needed)
fetch('users.json');
});