Skip to content

Instantly share code, notes, and snippets.

View MahdiY's full-sized avatar
🎯
Focusing

Mahdi Yousefi MahdiY

🎯
Focusing
View GitHub Profile
@MahdiY
MahdiY / serve.py
Created May 20, 2019 17:18
Serve a directory with python
import http.server
import socketserver
import os
PORT = 786
web_dir = os.path.join(os.path.dirname(__file__), '<DIR>')
os.chdir(web_dir)
Handler = http.server.SimpleHTTPRequestHandler
@MahdiY
MahdiY / git_pull.bat
Created May 16, 2019 08:08
Serve laravel, npm run watch and repeated git pull
git pull
TIMEOUT /T 30 /NOBREAK
git_pull.bat
@MahdiY
MahdiY / logit.php
Created August 10, 2018 06:39
easy logging in php
<?php
// log with error_log function
if( !function_exists('log_it') ){
function log_it() {
foreach( func_get_args() as $message )
if( is_array( $message ) || is_object( $message ) )
error_log( print_r( $message, true ) );
else
error_log( $message );
@anthonyeden
anthonyeden / wordpress-date.php
Last active May 8, 2023 07:38
Wordpress Date() and StrToTime() Functions
<?php
function wp_date_localised($format, $timestamp = null) {
// This function behaves a bit like PHP's Date() function, but taking into account the Wordpress site's timezone
// CAUTION: It will throw an exception when it receives invalid input - please catch it accordingly
// From https://mediarealm.com.au/
$tz_string = get_option('timezone_string');
$tz_offset = get_option('gmt_offset', 0);
@bladeSk
bladeSk / SQLite-PHP-quickstart.php
Last active May 28, 2024 11:30
SQLite3 PHP Quickstart Tutorial
<?php
// This file walks you through the most common features of PHP's SQLite3 API.
// The code is runnable in its entirety and results in an `analytics.sqlite` file.
// Create a new database, if the file doesn't exist and open it for reading/writing.
// The extension of the file is arbitrary.
$db = new SQLite3('analytics.sqlite', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
// Errors are emitted as warnings by default, enable proper error handling.
@jgravois
jgravois / _webserver.md
Last active April 12, 2024 00:21
a simple guide for getting a local web server set up

Do I have a web server running?


having a web server turned on doesn't necessarily mean you are serving pages on the world wide web. its what allows you to load your own static files (.html, .js etc.) in a browser via http://.

if you're not sure whether or not you have a web server running, no problem! its easy to confirm.

what happens when you visit http://localhost/?

@jniltinho
jniltinho / install_gogs_ubuntu.sh
Last active October 15, 2020 12:15
Install Gogs on Debian or Ubuntu
#!/bin/bash
## Install Gogs v0.11.4 + Nginx Webserver + Mysql
## On Debian, Ubuntu 64Bits
## Author: Nilton OS -- www.linuxpro.com.br
## Version: 3.5
### Tested on Ubuntu 16.04 LTS 64Bits
### Tested on Debian 8/9 64Bits
echo 'install_gogs_ubuntu.sh'
@rodrigopedra
rodrigopedra / gist:a4a91948bd41617a9b1a
Last active June 1, 2024 15:42
Laravel 5 Middleware for Database Transactions
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class DBTransaction
{
/**
* Handle an incoming request.
*
@koomai
koomai / PhpStorm Keyboard Shortcuts.md
Last active May 25, 2024 01:05
Frequently Used PhpStorm Keyboard Shortcuts

Note: Some of these shortcuts have been remapped for my own convenience (Preferences->Keymap). These are Mac shortcuts, just use the Windows/Linux equivalent of the Cmd/Option/Ctrl/Del keys.

####Search, Go to, Navigation ####

Cmd + P - Search file

Cmd + Shift + O - Search everywhere

(I swapped the above two recently because I use Cmd + P to search for files most of the time).

@jonhattan
jonhattan / drupal_backtrace_watchdog.php
Created February 14, 2014 14:02
When you want a quick lightweight backtrace in #drupal. Alternative to devel's ddebug_backtrace(). Use this snippet in conjunction with `drush wd-show --tail`
<?php
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $call) {
watchdog('backtrace', $call['function']);
}