Skip to content

Instantly share code, notes, and snippets.

Avatar

Saeid Mohadjer smohadjer

View GitHub Profile
@smohadjer
smohadjer / scrollByPixel.md
Last active Apr 29, 2016
scroll by pixel using arrow keys
View scrollByPixel.md

Scroll by one pixel via arrow keys up/down for finer control over scrolling. Use to debug scroll related issues.

$(window).on('keydown', function(event) {
	event.preventDefault();
	event.stopPropagation();
	
	var sctop = $(window).scrollTop();
	
	if (event.keyCode === 38) { //up arrow
@smohadjer
smohadjer / animate.js
Last active Sep 14, 2018
Scroll page via jQuery without invoking callback twice
View animate.js
//we use a promise so that callback is not invoked twice
$('html, body').animate({
scrollTop: top
}, 1000).promise().then(function() {
if (callback) {
//use setTimeout to make sure callback is invoked after all scroll event handlers in stack have executed
setTimeout(callback, 0);
}
});
@smohadjer
smohadjer / yii2.md
Last active Jun 11, 2020
Saeid's Yii2 Cookbook
View yii2.md

To display validation errors in a model:

$model->getErrors()

Custom validators

Custom validators can be written either inside a model or as a class in an external file so they can be used by different models.

@smohadjer
smohadjer / mariadb_time_zone_mac.md
Last active Feb 21, 2020
Setting MariaDB time zone to UTC on macOS
View mariadb_time_zone_mac.md

Setting Time Zone of MariaDB to UTC

  1. If you are logged in then exit mariadb and stop it via: brew services stop mariadb
  2. To populate time zone tables: To load the time zone tables from the command line, pass the zoneinfo directory path name to mysql_tzinfo_to_sql and send the output into the mysql program. If your root user has no password drop -p from below command:
    mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
    
  3. Open my.cnf (/usr/local/etc) and add following lines to it:
    [mysqld]
    default_time_zone='UTC'
    
@smohadjer
smohadjer / MariaDB.md
Last active Apr 22, 2020
Tips on using MariaDB
View MariaDB.md

If after a Mac OS update MariaDB or MySQL stop working and you get this error on login:\

mysql: Can't read dir of '/usr/local/etc/my.cnf.d' (Errcode: 2 "No such file or directory")
Fatal error in defaults handling. Program aborted

It's because my.conf.d folder doesn't exist. This will fix it:
mkdir /usr/local/etc/my.cnf.d


@smohadjer
smohadjer / virtual_host.md
Last active May 15, 2020
Updating virtual host
View virtual_host.md
  1. Uncomment the following line in httpd.conf:
    # Virtual hosts
    #Include /private/etc/apache2/extra/httpd-vhosts.conf (mac)
    #Include conf/extra/httpd-vhosts.conf (windows)
    
  2. Add below snippet to httpd-vhosts.conf (use backslash in windows):
    <VirtualHost *:80>
    
@smohadjer
smohadjer / php7.md
Last active Mar 7, 2020
PHP tips and tircks
View php7.md

Use foreach to loop arrays

foreach (array_expression as $value)
    statement
foreach (array_expression as $key => $value)
    statement

in_array — Checks if a value exists in an array

@smohadjer
smohadjer / .htaccess
Last active May 3, 2020 — forked from man-oi/.htaccess
htpasswd
View .htaccess
AuthType Basic
AuthName "only for valid users"
AuthUserFile /full/path/.htpasswd
Require valid-user
// If you don't have ssh access to your site, put the following command in a php file and upload it to your server to find out the full path to .htpasswd:
<?php echo realpath('./') . PHP_EOL; ?>
// You can create a .htpasswd using terminal:
htpasswd -c .htpasswd username
View Windows
Ctrl + Shift + S -> screenshot
Shift + 6 -> ^
Mac Terminal --> Windows Git Bash (MINGW64) --> Purpose
open . --> start . --> to open the current location in File Explorer
You can’t perform that action at this time.