Skip to content

Instantly share code, notes, and snippets.

View manashcse11's full-sized avatar

Manash Kumar Chakrobortty manashcse11

  • Cefalo
  • Dhanmondi, Dhaka
View GitHub Profile
// Redirect HTTP to HTTPS automatically
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#---- Existing project add in a new repo -------------//
go to project folder
git init
git add folder/file
git commit -m "init"
git remote add origin repo_url
git push -u origin master
#---- gitignore for already added file/directory: -------------//
Create .gitignore file and put directory/file there
public function parseSoapResponseToArray($response) {
$xml = preg_replace('/(<\/?)(\w+):([^>]*>)/', '$1$2$3', $response);
$xml = simplexml_load_string($xml);
$json = json_encode($xml);
return $responseArray = json_decode($json,true);
}
$request_xml = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.rating.uss.transforce.ca" xmlns:xsd="http://ws.rating.uss.transforce.ca/xsd" xmlns:xsd1="http://dto.uss.transforce.ca/xsd">
<soapenv:Header/>
<soapenv:Body>
http://jsfiddle.net/jv0wd073/188/

Observer Design Pattern:

  1. Give a way to avoid tight coupling between components.
  2. One object make itself observable(publisher), by adding a method that allows another objects observe itself.
  3. By registering to the observer list, registered objects can get notification when observable object change its state.

Factory Design Pattern:

  1. A class that has some methods, that creates object for you.
  2. Allows to create object runtime, without specifying the exact class.
  3. Just call the Factory with parameter(by which Factory decide), then Factory will create specific object for you.
@manashcse11
manashcse11 / mysql-remote-db-from-local-ssh-tunneling.md
Last active August 21, 2017 06:02
#mysql #remote-db-from-local # Connect remote mysql using HeidiSQL

If you can ssh then you can connect with the remote database by ssh tunneling. Open babun & write below command. Also you can add to to alias

ssh -L 3300:localhost:3306 root@107.170.73.134

Then open HeidiSQL -> Session Manager -> New

Hostname: 127.0.0.1

User: dbuser

Password: dbpassword

Port: 3300

@manashcse11
manashcse11 / laravel-helper-class-for-commonly-used-methods.md
Last active September 10, 2017 16:33
#Laravel #Helper-Service-Provider

Having a folder with multiple files allows us to avoid one big file that gets too long and unmanageable.

  1. Create a folder in app directory named "Helpers"

  2. Run command "php artisan make:provider HelperServiceProvider"

  3. Within the register method of Providers/HelperServiceProvider.php add below lines:

     foreach (glob(app_path().'/Helpers/*.php') as $filename){
         require_once($filename);
    

}

@manashcse11
manashcse11 / mysql.md
Last active September 14, 2017 09:46
#mysql MySQL query snippets

Insert with select

INSERT INTO table1 ( column1 )
SELECT  col1
FROM    table2  

Show key value row based (e.g., meta) table as columns with main table

Example: if you have users(id, email) and user_meta(user_id, key, value) tables where you have phone, age etc keys in user_meta but need to show these as columns with users table

@manashcse11
manashcse11 / curl-update.sh
Last active September 20, 2017 06:20
#curl version update #curl-update-ubuntu 12.04
mkdir ~/curl
cd ~/curl
Try below command to download latest version of curl
wget http://curl.haxx.se/download/curl-7.50.2.tar.bz2
If the command doesn't work then try to download the file using browser in local machine. Then scp it to server in the ~/curl directory
@manashcse11
manashcse11 / laravel-collection-group-by-with-sum.php
Last active September 7, 2022 14:50
#Laravel collection #group by with sum
<?php
$collection = collect([
['item_id' => 10, 'status_id' => 1, 'point' => 3],
['item_id' => 11, 'status_id' => 2, 'point' => 2],
['item_id' => 12, 'status_id' => 3, 'point' => 4],
['item_id' => 13, 'status_id' => 3, 'point' => 1],
]);
$grouped = $collection->groupBy('status_id')
->map(function ($item) {