Skip to content

Instantly share code, notes, and snippets.

View amritms's full-sized avatar
🎯
Focusing

Amrit Man Shrestha amritms

🎯
Focusing
  • Toronto, ON, Canada
View GitHub Profile
FROM php:7.0.4-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
@amritms
amritms / Kernel.php
Created February 2, 2019 18:43 — forked from ricardocanelas/Kernel.php
Laravel / Locale (middleware)
<?php // app/Http/kernel.php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
//...
protected $middlewareGroups = [
@amritms
amritms / React Native Clear Cache
Created December 1, 2018 09:14 — forked from jarretmoses/React Native Clear Cache
Clearing the Cache of your React Native Project
RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
npm >= 5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
@amritms
amritms / eloquent-cheatsheet.php
Created September 20, 2018 05:28 — forked from hassansin/eloquent-cheatsheet.php
Laravel 5 Eloquent CheatSheet #laravel #eloquent
Model::
/*Select*/
select('col1','col2')
->select(array('col1','col2'))
->select(DB::raw('businesses.*, COUNT(reviews.id) as no_of_ratings, IFNULL(sum(reviews.score),0) as rating'))
->addSelect('col3','col4')
->distinct() // distinct select
/*From*/
@amritms
amritms / dropzone-form.html
Last active September 20, 2018 05:58
WIP - Laravel form with Multiple Images upload using Dropzone
<!DOCTYPE html>
<html>
<head>
<title>Laravel form with Multiple Images upload using Dropzone</title>
<meta name="_token" content="{{csrf_token()}}" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/dropzone.js"></script>
</head>
@amritms
amritms / deployer.php
Created August 8, 2018 08:47
deployer script to deploy to server
<?php
namespace Deployer;
require 'recipe/laravel.php';
// Project name
set('application', <Application Name>);
// Project repository
@amritms
amritms / getByValueFromArrayOfObjects.js
Created March 20, 2018 09:08
Get Value from Array of Objects
function getByValueFromArrayOfObjects(arr, value) {
var result = [];
arr.forEach(function (o) {
if (o.id == value) result.push(o);
});
return result ? result[0].username : '-'; // or undefined
}
@amritms
amritms / convertTimestampToDate.js
Created March 20, 2018 08:58
Convert MySQL timestamp to date in javascript
function convertTimestampToDate(timestamp, format='y-m-d'){
// Split timestamp into [ Y, M, D, h, m, s ]
var t = timestamp.split(/[- :]/);
// Apply each element to the Date function
var d = new Date(Date.UTC(t[0], t[1] - 1, t[2], t[3], t[4], t[5]));
var dateString = '';
var fullYear = d.getFullYear();
var month = d.getMonth() + 1;
@amritms
amritms / http-status-codes.md
Created March 15, 2018 05:16
http status codes
200: OK. The standard success code and default option.
201: Object created. Useful for the store actions.
204: No content. When an action was executed successfully, but there is no content to return.
206: Partial content. Useful when you have to return a paginated list of resources.
400: Bad request. The standard option for requests that fail to pass validation.
401: Unauthorized. The user needs to be authenticated.
403: Forbidden. The user is authenticated, but does not have the permissions to perform an action.
404: Not found. This will be returned automatically by Laravel when the resource is not found.
500: Internal server error. Ideally you're not going to be explicitly returning this, but if something unexpected breaks, this is what your user is going to receive.

503: Service unavailable. Pretty self explanatory, but also another code that is not going to be returned explicitly by the application.

@amritms
amritms / phpspec-reference-guide.md
Created March 15, 2018 05:07
PHPSpec reference guide