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
@amritms
amritms / docker_cheatsheet.sh
Last active February 26, 2018 12:37
Docker Cheatsheet
##############################################################################
# DOCKER
##############################################################################
docker build -t friendlyname . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyname # Same thing, but in detached mode
docker exec -it [container-id] bash # Enter a running container
docker ps # See a list of all running containers
@amritms
amritms / bulk_update.php
Last active January 31, 2018 03:41
Bulk update for marks and remarks
/**
* Bulk update for marks and remarks
* @param array $values
* @return mixed
*/
public static function updateValues(array $values)
{
$table = ExamScore::getModel()->getTable();
$marks = [];
$remarks = [];
@amritms
amritms / macro.md
Created January 30, 2018 10:35 — forked from brunogaspar/macro.md
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@amritms
amritms / massInsertOrUpdate.php
Created January 30, 2018 08:15 — forked from RuGa/massInsertOrUpdate.php
Mass (bulk) insert or update on duplicate for Laravel 4/5
/**
* Mass (bulk) insert or update on duplicate for Laravel 4/5
*
* insertOrUpdate([
* ['id'=>1,'value'=>10],
* ['id'=>2,'value'=>60]
* ]);
*
*
* @param array $rows
@amritms
amritms / switch_php_versions
Created December 29, 2017 08:34
switch between php 5.6 and php 7.1 versions in ubuntu
On your system, if you have installed multiple versions of PHP (eg PHP 7.1 and PHP 5.6 both). PHP 7.1 is running as default PHP for Apache and CLI. For any requirement, you need to use PHP 5.6. Then you don’t need to remove PHP 7.1. You can simply switch your PHP version to default used for Apache and command line.
For example, your server has PHP 7.1 and PHP 5.6 both version’s installed. Now following example will help you to switch between both versions. The PHP 5.6 is configured as default PHP version for Apache and CLI. Let’s make PHP 7.1 as default PHP for Apache server and CLI.
Apache:-
sudo a2dismod php5.6
sudo a2enmod php7.1
sudo service apache2 restart
Command Line:-
@amritms
amritms / 0_reuse_code.js
Created June 15, 2017 05:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Thanks to Michael Conigliaro
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@amritms
amritms / php: dump_variables
Created July 29, 2013 06:54
replacement of dump and exit php function
/**
* Dump helper. Functions to dump variables to the screen, in a nicley formatted manner.
* @author Joost van Veen
* @version 1.0
*/
if (!function_exists('dump')) {
function dump ($var, $label = 'Dump', $echo = TRUE)
{
// Store dump in variable
ob_start();
@amritms
amritms / js: in_array
Created July 29, 2013 06:40
php in_array equivalent in javascript
Array.prototype.
Array.prototype.inArray = function(needle) {
for (var i = 0, len = this.length; i < len; i++) {
if (this[i] === needle) {
return true;
}
}
return false;
}
//Now all arrays will have the new method.Let's test: