Skip to content

Instantly share code, notes, and snippets.

View locvfx's full-sized avatar

Dylan Lopez locvfx

View GitHub Profile
@locvfx
locvfx / CI modular
Created December 26, 2018 14:58
Call method cross module
$this->load->module('dashboard');
$this->dashboard->method();
@locvfx
locvfx / crop-resize-image
Created December 19, 2018 13:37
Crop and resize image
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
@locvfx
locvfx / random.sql
Last active November 19, 2018 03:10
SQLl to select random record in huge data table #SQL
SELECT `post_title` FROM bf_article_posts AS r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM bf_article_posts)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 10
#https://stackoverflow.com/questions/4329396/mysql-select-10-random-rows-from-600k-rows-fast
#http://jan.kneschke.de/projects/mysql/order-by-rand/
@locvfx
locvfx / convert post's title to post's slug
Created August 24, 2018 08:47
convert post's title to post's slug #MYSQL
UPDATE TABLE_NAME SET post_slug = LOWER(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM(post_title), ':', ''), '’', ''), ')', ''), '(', ''), ',', ''), '\\', ''), '\/', ''), '\"', ''), '?', ''), '\'', ''), '&', ''), '!', ''), '.', ''), ' ', '-'), '--', '-'), '--', '-'))
@locvfx
locvfx / Get the first element of an array
Created August 24, 2018 07:39
Get the first element of an array #php
array_values($array)[0];
@locvfx
locvfx / constants
Created August 24, 2018 03:13
Usefull constants #CI #BF
BFPATH - > '/bonefire/'
FCPATH -> '/public/'
BASEPATH -> '/system/'
//in CI_Bonfire : /bonfire/ci3/
APPPATH -> '/application/'
#return filename
basename($path);
@locvfx
locvfx / html + javascript
Created August 23, 2018 09:16
Display thumbnail image when mouse hover #javascript
<span class="help-block"><a rel="featured_image_popover" href="<?=$data['post_featured_image'];?>" data-img="<?=$data['post_featured_image'];?>" target="_blank">image's URL</a></span>
$('a[rel=featured_image_popover]').popover({
html: true,
trigger: 'hover',
placement: 'bottom',
content: function () { return '<img class="img-responsive" src="' + $(this).data('img') + '" />'; }
});
@locvfx
locvfx / sitemao.xml
Created August 11, 2018 15:58
Sitemap example #xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>http://www.example.com/foo.html</loc>
<image:image>
<image:loc>http://example.com/image.jpg</image:loc>
<image:caption>Dogs playing poker</image:caption>
</image:image>
@locvfx
locvfx / .css
Created August 8, 2018 14:31
How To Make a Responsive 100% Width YouTube iFrame Embed #HTML #CSS #youtube
.container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.25%;
}
.video {
position: absolute;
top: 0;
left: 0;
@locvfx
locvfx / output-json.php
Created August 5, 2018 17:41
How to convert MYSQL data to JSON using PHP
<?php
// Initialize variable for database credentials
$dbhost = 'hostname';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'sakila';
//Create database connection
$dblink = new mysqli($dbhost, $dbuser, $dbpass, $dbname);