Skip to content

Instantly share code, notes, and snippets.

@enopanen
enopanen / gist:65bb8ff1dc1c83280f270bf7b99b8093
Last active October 3, 2023 09:40
Get Color From Featured Image and Update Product with custom attribute
<?php
// Include WordPress functionality, replace this path with the actual path to your wp-load.php
include('/path/to/wordpress/wp-load.php');
// Color groups in PHP associative array
$colorGroups = [
"Black" => ["#000000", "#1a1a1a", "#333333"],
"Blue" => ["#0000cc", "#1E90FF", "#4682B4"],
"Bronze" => ["#b87333", "#DAA520", "#CD7F32"],
"Brown" => ["#8b4513", "#A52A2A", "#D2691E"],
@enopanen
enopanen / mysqli_connect
Created December 8, 2013 01:21
MySQLi Connect Example
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
@enopanen
enopanen / apache_virtual_host
Created December 7, 2013 22:45
Apache virtual host file example
# domain: example.com
# public: /home/example_user/public/example.com/
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin [email protected]
ServerName www.example.com
ServerAlias example.com
# Index file and Document Root (where the public files are located)
@enopanen
enopanen / create_database
Created December 7, 2013 22:44
MySQL commands to create database and user.
mysql -u root -p
create database exampleDB;
grant all on exampleDB.* to 'example_user' identified by '5t1ck';
flush privileges;
quit
@enopanen
enopanen / vimrc
Created December 7, 2013 22:39
Vim configuration
syntax on " Syntax highlighting
filetype plugin indent on " Enable filetype-specific plugins
set title
set laststatus=2 " Always show the statusline
set encoding=utf-8 " unicode!
"new **********************
@enopanen
enopanen / robots_disallow_all
Created December 7, 2013 22:38
Disallow all bots crawling site
User-agent: *
Disallow: /
@enopanen
enopanen / find_full_path_to_directory
Created December 7, 2013 22:36
Find full path to the current php directory
<?php
$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";
?>
@enopanen
enopanen / new_gist_file_0
Created December 5, 2013 17:07
Photo Uploader resides in /DOCUMENT_ROOT/admin/index.php and uses imagick
<?php
if(isset($_POST['addImage'])) {
//echo "<pre>" . print_r($_FILES, true) . "</pre>" ;
if(isset($_FILES['gMainImg'])) {
$tmpFile = $_FILES["gMainImg"]["tmp_name"];
$fileName = "../images/gallery/" .time(). ".jpg" ;
echo getcwd();
@enopanen
enopanen / CDN
Created December 4, 2013 01:23
Google's CDN jQuery
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- jQuery: Print Page -->
$('a.printPage').click(function(){
window.print();
return false;
});
<!-- HTML: Print Page -->
<div>
<a class="printPage" href="#">Print</a>
</div>