Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
😁
Having fun

Jose Robinson jrobinsonc

😁
Having fun
View GitHub Profile
@jrobinsonc
jrobinsonc / send-request.php
Last active June 26, 2017 18:04
Send GET and POST requests with file_get_contents.
<?php
function sendRequest($method, $url, $content = '', $headers = []) {
$opts = [
'http' => [
'method' => $method,
'header' => implode("\r\n", $headers),
'content' => $content
]
];
@jrobinsonc
jrobinsonc / git-change-author.sh
Created June 26, 2017 12:40
Change the name and e-mail of multiple commits in Git
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@jrobinsonc
jrobinsonc / remove-mysql.md
Last active June 5, 2018 12:45
Remove MySQL-MariaDB in Ubuntu
apt-get purge -y mysql* mariadb* \
    && apt-get autoremove -y \
    && apt-get autoclean -y \
    && rm -rf /etc/mysql /var/lib/mysql
@jrobinsonc
jrobinsonc / responsive-iframe.css
Created May 31, 2017 16:25
Responsive Iframe
.iframe-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
}
.iframe-container iframe {
position: absolute;
@jrobinsonc
jrobinsonc / get-ip.php
Last active December 30, 2019 15:33
Get user IP
<?php
/**
* Returns the IP of the user.
*
* @return string|false
*/
function getIP() {
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
$val = filter_input(INPUT_SERVER, $key);
@jrobinsonc
jrobinsonc / read-file.php
Created May 3, 2017 13:03
Read files in PHP no matter line endings.
<?php
ini_set('auto_detect_line_endings', true);
$states_list = [];
$handle = @fopen('states-list.csv', 'r');
if ($handle !== false) {
while (!feof($handle)) {
@jrobinsonc
jrobinsonc / README.md
Last active April 28, 2017 13:01
GIT Hooks

GIT Hooks

Prevent commit into master. You can use a pre-commit hook.

#!/bin/bash
if test $(git rev-parse --abbrev-ref HEAD) = "master" ; then
  echo "Cannot commit on master."
  exit 1
fi
@jrobinsonc
jrobinsonc / li.css
Created April 26, 2017 15:38
HTML list custom styles
ol{
list-style:none;
counter-reset:li;
padding:8px 0px 1px;
left:-7px;
width:290px;
}
li{
position:relative;
margin:0 0 10px 0;
@jrobinsonc
jrobinsonc / wget.md
Last active September 29, 2017 21:09
wget

wget

wget -r -l4 --spider -D example.com http://example.com

Useful options

Option Details
@jrobinsonc
jrobinsonc / shortcode.php
Created April 13, 2017 13:42
Wordpress shortcode parser
<?php
$content = get_the_content();
$shortcodes_data = [];
// This will extract the shortcodes named [coupon_form] and [page_settings].
if (preg_match_all('/\[(\[?)(coupon_form|page_settings)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/s', $content, $matches)
&& array_key_exists(2, $matches))
{
foreach ($matches[2] as $shortcode_key => $shortcode_name) {