Skip to content

Instantly share code, notes, and snippets.

View hr-sadooghi's full-sized avatar

Hamidreza Sadooghi hr-sadooghi

  • Australia, Sydney
View GitHub Profile
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
direction: rtl;
text-align: right;
}
.container {
@hr-sadooghi
hr-sadooghi / docker-cheatsheet.md
Last active June 1, 2020 18:14
Some useful docker commands for me
@hr-sadooghi
hr-sadooghi / use-JSON_OBJECT-as-GROUP_CONCAT.sql
Created December 16, 2017 08:25
use-JSON_OBJECT-as-GROUP_CONCAT
#Schema:
CREATE TABLE posts(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , title VARCHAR(500) NOT NULL , body TEXT NOT NULL);
CREATE TABLE keywords(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(500) NOT NULL);
CREATE TABLE post_keyword(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, post_id int NOT NULL, keyword_id INT NOT NULL );
#Test Data:
INSERT INTO posts VALUES (NULL, 'post-title-A', 'This Content Of Post A'), (NULL , 'post-title-B', 'This Content Of Post B'), (NULL , 'post-title-C', 'This Content Of Post C');
INSERT INTO keywords VALUES (NULL, 'keyword-A'), (NULL, 'keyword-B'), (NULL, 'keyword-C');
INSERT INTO post_keyword VALUES (NULL, 1,1), (NULL, 1,2), (NULL, 1,3), (NULL, 2,2), (NULL, 3,1);
@hr-sadooghi
hr-sadooghi / bakfile.sh
Last active September 24, 2017 12:11
This bash script create backup from specified dir or files with current Jalali datetime postfix.
#!/bin/bash
# This file depend on jdate command
# You can build jdate from source with this guide: https://wiki.ubuntu.ir/wiki/Jcal
if [$1 = ]
then
echo "no files given"
exit 0
fi
@hr-sadooghi
hr-sadooghi / gulpfile.js
Last active August 31, 2017 17:38
Simple sample of gulpjs file. Tasks of this gulpfile is: combine js file together, run babel to convert ES6 to lower compatible version, remove debugging commands like console.log, minify, store in two place.
const gulp = require('gulp');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const stripDebug = require('gulp-config-strip-debug');
const minifyCSS = require('gulp-minify-css');
const babel = require('gulp-babel');
const include = require("gulp-include");
const gutil = require('gulp-util');
@hr-sadooghi
hr-sadooghi / detect-nix-os.sh
Created July 29, 2017 16:44
This shell script find out which distro and version of *nix os used.
#!/bin/sh
# Detects which OS and if it is Linux then it will detect which Linux Distribution.
# Thanks to this contribution that we take it from this site:
# http://www.unix.com/unix-for-advanced-and-expert-users/21468-machine.html#post83185
# Test result on ubuntu 14.04 LTS:
# Linux Debian jessie/sid ( 3.13.0-32-generic x86_64)
OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`

Laravel Notes

  • make model & controller & migration with one command:
php artisan make:model Post -mc
  • create only Controller for resource(CRUD actions)
@hr-sadooghi
hr-sadooghi / fa2EnDigit-en2FaDigit.sql
Created February 27, 2017 08:09
english digit to persian digit and reverse
DROP FUNCTION IF EXISTS fa2EnDigit;
DELIMITER $$
CREATE FUNCTION fa2EnDigit(str TEXT) RETURNS TEXT
BEGIN
DECLARE t TEXT;
SET t = str;
SET t = REPLACE(t, '۱', '1');
SET t = REPLACE(t, '۲', '2');
SET t = REPLACE(t, '۳', '3');
SET t = REPLACE(t, '۴', '4');
@hr-sadooghi
hr-sadooghi / find-dependent-tables.sql
Created February 27, 2017 07:28
MySQL: How do I find out which tables reference a specific table?
select table_name
from information_schema.KEY_COLUMN_USAGE
where table_schema = 'database_name'
and referenced_table_name = 'table_name';
-- http://stackoverflow.com/questions/754512/mysql-how-do-i-find-out-which-tables-reference-a-specific-table/754582#754582
@hr-sadooghi
hr-sadooghi / fix-arabic-char-inside-string.sql
Created February 27, 2017 07:18
fix-arabic-char-inside-string
--fix
UPDATE post SET body = replace(body, 'ي', 'ی') WHERE body LIKE '%ي%';
--fix
UPDATE post SET body = replace(body, 'ك', 'ک') WHERE body LIKE '%ك%';
--find how many post has arabic 'ي'
select count(*) from post where body like '%ي%';
--find how many post has arabic 'ك'