Skip to content

Instantly share code, notes, and snippets.

View ngugijames's full-sized avatar
🇰🇪
.

James Ngugi ngugijames

🇰🇪
.
View GitHub Profile
#Filter:
cd /etc/fail2ban/filter.d
[Definition]
#failregex = <HOST> - - \[(\d{2})/\w{3}/\d{4}:\1:\1:\1 -\d{4}\] "POST /admin/ HTTP/1.1"
#failregex = ^<HOST> - .* "POST /admin/ HTTP/1.1" 499
#failregex = ^<HOST> - .* "(GET|POST|HEAD).*HTTP.*" 404 .*$
#failregex = ^<HOST> - .* "(GET|POST|HEAD) /admin/ HTTP.*" .*$
@ngugijames
ngugijames / officetophp.php
Created January 11, 2016 10:42
DOC, DOCX, PPT, XLSX to TXT in PHP
/*determine th file extension
$file_name = $_FILES['image']['name'];
$file_extn = end(explode(".", strtolower($_FILES['image']['name'])));
if($file_extn == "doc" || $file_extn == "docx"){
}elseif($file_extn == "rtf"){
}
*/
@ngugijames
ngugijames / longPolling.js
Created October 28, 2015 07:22 — forked from jasdeepkhalsa/longPolling.js
Simple Long Polling Example with JavaScript and jQuery by Tian Davis (@tiandavis) from Techoctave.com (http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery)
// Long Polling (Recommened Technique - Creates An Open Connection To Server ∴ Fast)
(function poll(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json", complete: poll, timeout: 30000 });
})();
@ngugijames
ngugijames / gist:bf08e32ffabf164099686a46f59b6e2b
Created August 18, 2020 11:46
Fail2Ban: Unban IP address from all jails
for jail in $(fail2ban-client status | grep 'Jail list:' | sed 's/.*Jail list://' | sed 's/,//g'); do fail2ban-client set $jail unbanip IP_ADDRESS_HERE; done
/**
* Special thanks to http://webcheatsheet.com/php/reading_the_clean_text_from_rtf.php
*/
<?php
// Function that checks whether the data are the on-screen text.
// It works in the following way:
// an array arrfailAt stores the control words for the current state of the stack, which show that
// input data are something else than plain text.
// For example, there may be a description of font or color palette etc.
@ngugijames
ngugijames / backup_script.sh
Created December 30, 2018 12:57
MySQL backup script
#!/bin/sh
BACKUP=/var/www/html/mysql_backup/backups
cd $BACKUP
sudo mkdir `date '+%d-%m-%Y'`
NOW=$(date +"%d-%m-%Y")
MUSER="user"
MPASS="pass"
MHOST="host"
MYSQL="$(which mysql)"
@ngugijames
ngugijames / l3_log_replacer.php
Last active November 2, 2017 09:51
find L3 log usages and replace with L5 equivalents using PHPStorm
<?php
//Search For:
Log::(.*?)\((.*[\(\)]*)\);
//Replace with
Log::info("$1", $2);
// Replaces Log::api_unreachable(..) with something like Log::info("api_unreachable", ..);
@ngugijames
ngugijames / validation.php
Created August 16, 2017 08:52
showing :value in laravel validation errors
//in controller
$validator = Validator::make(['one','two','three'], [
'*' => 'exists:table,name',
], [
'exists' => '`:value` does not exist.',
]);
//in service provider boot
$this->app->validator->resolver(function($translator, $data, $rules, $messages, $attributes)
@ngugijames
ngugijames / remote-git.md
Created July 11, 2017 15:58 — forked from Integralist/remote-git.md
Basic set-up of remote git repository on a standard server

Set-up remote git repository on a standard server

The first thing to do is to install Git on the remote server.

Once you do that the rest of the process is split into three sections:

  1. Server set-up
  2. Local set-up (push commits)
  3. Server (pull commits)
@ngugijames
ngugijames / Ussd-varying-questions.php
Last active August 30, 2016 10:20
Ussd with varying questions and responses
<?php
/**
* Collaborated with http://github.com/pittgikera
*/
$text = $_GET['text'];
//$questions = "How was is it? # Was it enjoyable?# Did you have fun? # Will you come back?";
$questions = "";