Skip to content

Instantly share code, notes, and snippets.

View rajitha-bandara's full-sized avatar

Rajitha Bandara rajitha-bandara

View GitHub Profile
@rajitha-bandara
rajitha-bandara / gist:ce5f0f58547f9968b5d8f086b010f36b
Created June 3, 2018 04:13
Laravel eloquent delete with handling integrity constraint violation
try {
$category->delete();
}
catch (\Illuminate\Database\QueryException $e) {
if($e->getCode() == "23000"){ //23000 is sql code for integrity constraint violation
// return error to user here
}
}
@rajitha-bandara
rajitha-bandara / handlebarjs-notes
Created March 23, 2018 01:57
Handlebar.js notes
1. Add dynamic css, js
https://github.com/ericf/express-handlebars/issues/15
https://stackoverflow.com/questions/25300017/how-to-ensure-the-javascript-is-at-the-bottom-of-the-code-in-express-handlebars
Generate ssh in web server
go to /var/www
sudo -u www-data ssh-keygen
sudo cat .ssh/id_rsa.pub
set this in gitlab deployment keys
sudo -u www-data mkdir xxxxxx
@rajitha-bandara
rajitha-bandara / gist:0254c6ee21b10bfb0e7c32de75b61d3a
Last active December 18, 2017 19:41
WordPress Multi Purpose Themes
https://8degreethemes.com/wordpress-themes/
https://www.navthemes.com/free-wordpress-theme/constra/
http://demo.navthemes.com/?demo=plain-blog-theme
http://demo.navthemes.com/?demo=truewest-free-multipurpose-wordpress-theme&c=rsOSrXFBK
http://demo.mysterythemes.com/owner/
@rajitha-bandara
rajitha-bandara / carbon.php
Last active October 13, 2017 11:23
Carbon Date Snippets
Format date time using Carbon
\Carbon\Carbon::createFromFormat($from, $value)->format($to);
\Carbon\Carbon::createFromFormat('Y-m-d H:i:s', '2017-12-10 01:00:00')->format('d/m/Y H:i')
Validate & format Carbon date
if (! function_exists('carbon_date_or_null_if_zero')) {
function convert_datetime_to_carbon($value, $from = 'Y-m-d H:i:s', $to = 'd/m/Y H:i')
{
if(empty($value)){
return null;
LOAD DATA LOCAL INFILE "C:/Users/xxx/e7849261fe2785926565f6c9c4dea6e957c3c837.csv"
INTO TABLE contacts
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
@rajitha-bandara
rajitha-bandara / gist:b513c7d65b5b02fd96512e44febc5852
Last active October 5, 2017 06:48
Set up Cent OS 7 Web Server
Manage Security
1.Allow HTTP Service theough firewall
Open Predefined Service
https://www.rootusers.com/how-to-open-a-port-in-centos-7-with-firewalld/
2. Change SSH Port
https://www.globo.tech/learning-center/change-ssh-port-centos-7/
3. Disable Root Login
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-7
@rajitha-bandara
rajitha-bandara / woocommerce_products_delete.php
Created September 29, 2017 16:01
WordPress Bulk Delete - WooCommerce Products
require_once( 'wp-load.php' );
global $wpdb;
$sql_1 = "DELETE FROM ".$wpdb->prefix."term_relationships WHERE object_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'product');";
$sql_2 = "DELETE FROM ".$wpdb->prefix."postmeta WHERE post_id IN (SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'product');";
$sql_3 = "DELETE FROM ".$wpdb->prefix."posts WHERE post_type = 'product';";
$sql_4 = "DELETE relations.*, taxes.*, terms.*
FROM ".$wpdb->prefix."term_relationships AS relations
https://htmlpdfapi.com/blog/free_html5_invoice_templates
use Symfony\Component\HttpFoundation\StreamedResponse;
$response = new StreamedResponse(function() use ($request, $data) {
while (true) {
echo 'data: ' . json_encode(['data' => $data]) . "\n\n";
ob_flush();
flush();
usleep(10000000);
}
});