Skip to content

Instantly share code, notes, and snippets.

@aquasmit
aquasmit / sqlserver-create-new-schema.sql
Created July 10, 2018 14:08
sqlserver-create-new-schema
USE AdventureWorks2012;
GO
CREATE SCHEMA [stg]
@aquasmit
aquasmit / create-table-like-alternative-for-sqlserver.sql
Created July 10, 2018 14:07
sqlserver-create-table-like-alternative-for-sqlserver
/*This will create new table 'newTableNameToBeCreated' with same structure as 'myRealTable' */
/* no data will be inserted into the new table */
SELECT *
into newTableNameToBeCreated
FROM myRealTable
where 0=1
@aquasmit
aquasmit / sqlserver-get-rows-count-on-large-table.sql
Last active July 10, 2018 14:03
SQL server - get approximate count of rows from a table with large number of records
use [SALES]
/*This returns approximate count*/
EXEC sp_spaceused N'dbo.Customers';
GO
@aquasmit
aquasmit / laravel.js
Created April 24, 2018 02:15 — forked from soufianeEL/laravel.js
You use Laravel 5 and you want to send a DELETE request without creating a form? This will handle the form-creation bits for you dynamically, similar to the Rails implementation. To use, import script, and create a link with the `data-method="DELETE"` and `data-token="{{csrf_token()}}"` attributes.
/*
Exemples :
<a href="posts/2" data-method="delete" data-token="{{csrf_token()}}">
- Or, request confirmation in the process -
<a href="posts/2" data-method="delete" data-token="{{csrf_token()}}" data-confirm="Are you sure?">
*/
(function() {
@aquasmit
aquasmit / gist:5a105610f1c21e1256c51cfecd22fb42
Created December 15, 2017 07:03 — forked from digitaljhelms/gist:4287848
Git/GitHub branching standards & conventions

Branching

Quick Legend

Description, Instructions, Notes
Instance Branch
@aquasmit
aquasmit / backup-mongodb-database.md
Last active September 17, 2017 03:53
Backup MongoDB database

Backup MongoDB database

  • Step 1: Create Backup folder

sudo mkdir /var/backups/mongobackups

  • Step 2: Backup database with following command

sudo mongodump -h SERVER_NAME:PORT -u DATABASE_USER -p PASSWORD --db appdb --out /var/backups/mongobackups/`date +"%m-%d-%y"`

@aquasmit
aquasmit / angularjs-send-post-data.md
Created December 19, 2016 04:22
AngularJs - send data with $http.post()

Send data with $http.post() in AngularJs

In AngularJs Controller

....
  var config = {
      headers : {
 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
@aquasmit
aquasmit / laravel-query-many-to-many-relationship.md
Last active August 23, 2021 04:00
Laravel - Eloquent - query many to many relationship

Laravel - Eloquent - query many to many relationship

Example:

Table 1: posts

Table 2: categories

Pivot Table: category_post with foreign keys category_id, post_id

@aquasmit
aquasmit / laravel-image-resize.md
Last active December 19, 2016 04:01
Laravel - perfect image resize in intervention

If you are using intervention in laravel for image resize then below snippet you can use to resize with max width and max height and maintaing aspect ration.

            
            $img = Image::make($file);            
            $new_filename = 'newname.'.$file->getClientOriginalExtension();	
            $img->widen(660, function($constraint){
            	 $constraint->upsize();	//this makes sure no upsize
            })->heighten(330, function($constraint){
 $constraint-&gt;upsize();	//this constraint makes sure no upsize
@aquasmit
aquasmit / try-catch-find-or-fail-exception.md
Created December 19, 2016 03:44
Laravel - Try Catch FindOrFail Exceptions

Following should work if you want to use try/catch for FindOrFail

use Illuminate\Database\Eloquent\ModelNotFoundException;
...
try {
  $current = Promovote::where('module_id',$data['module'])->firstOrFail($id);
} catch (ModelNotFoundException $ex) {
  // Error handling code
}