Skip to content

Instantly share code, notes, and snippets.

View klebinhopk's full-sized avatar
🏠
Working from home

Kleber Pereira klebinhopk

🏠
Working from home
View GitHub Profile
@klebinhopk
klebinhopk / MultiCurl.class.php
Created March 6, 2020 12:06
MultiCurl class PHP
<?php
/**
* MultiCurl class library is a PHP solution for work with MULTI CURL extension.
* It provides to execute some parallel HTTP requests with limit of downloaded
* size. Example: start 100 downloads with 2 parallel sessions, and get only
* first 100 Kb per session.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@klebinhopk
klebinhopk / gist:41d87f1aff15059869718e09730b335a
Created November 18, 2018 12:57
MYSQL, EXPORT CSV: Export to csv straight from MySQL - note MySQL may not have permission to write this file to your app directory
$app_directory = dirname(BASEPATH);
$export_location = $app_directory . '/assets/exports/';
$filename = "export-" . date('Y-m-d H-i-s') . ".csv";
$export_location = $export_location . $filename;
$query = $this->db->query("
SELECT users.id, users.firstname, users.lastname, users.email, users.dob, messages.line1, messages.line2, messages.line3, messages.barcode_selected, address.my_address, address.firstname, address.lastname, address.address1, address.address2, address.town, address.postcode, address.datecreated
FROM users
JOIN messages
@klebinhopk
klebinhopk / gist:360c17a6fea284620bfba6f8e13e1466
Created November 18, 2018 12:57
PHP, PDO, EXPORT, EXPORT TO CSV: Use PDO to create a standalone php script for use in cron jobs where codeigniter urls can't be run by cron
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
die(':)');
}
echo "Cron is running";
$hostname = 'localhost';
$username = 'cl50-whiskey_p';
$password = 'rmBRsm!kK';
@klebinhopk
klebinhopk / gist:204975332e85e27afa2507be107479b6
Created November 18, 2018 12:52
Codeigniter, Model, PHP: Check if user already exists in database
public function user_exists($user_id)
{
$this->db->where('user_id', $user_id);
$query = $this->db->get('sometablenamehere');
if($query->num_rows >= 1)
{
//if query finds one row relating to this user then execute code accordingly here
}
}
@klebinhopk
klebinhopk / scraper.js
Created June 21, 2018 18:02
Google news scraper
const request = require('request');
const cheerio = require('cheerio');
var searchTerm = 'tech';
var searchUrl = 'https://www.google.com/search?q=' + searchTerm + '&tbm=nws';
var savedData = [];
request(searchUrl, function(err, response, html) {
// First we'll check to make sure no errors occurred when making the request
if (err) {
@klebinhopk
klebinhopk / insert-posts.php
Created November 11, 2017 01:31
Insert a post into WordPress from an external script
<?php
// Load WordPress
require_once 'path/to/www/wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
// Set the timezone so times are calculated correctly
date_default_timezone_set('Europe/London');
// Create post
@klebinhopk
klebinhopk / php-html-css-js-minifier.php
Created July 24, 2016 22:03 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
/**
* ----------------------------------------------------------------------------------------
* Based on `https://github.com/mecha-cms/mecha-cms/blob/master/engine/plug/converter.php`
* ----------------------------------------------------------------------------------------
*/
@klebinhopk
klebinhopk / functions.php
Created July 20, 2016 22:40 — forked from lenivene/functions.php
Insert thumbnail (attachment) post by url
<?php
/**
* Insert thumbnail by URL
* Is very good to execute wp_insert_post
*
* @author Lenivene Bezerra
* @param string $url Image url external or no
* @param int $post_ID Post id to insert thumbnail
* @return ID Thumbnail | WP_Error
*/