Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nosajhpled
nosajhpled / PHP - Remove All Characters except Letters, Numbers and Spaces
Created December 4, 2022 15:01
PHP - Remove All Characters except Letters, Numbers and Spaces
I do this way to often:
preg_replace('/[^a-zA-Z0-9 ]/','',$string)
#PHP#REGEX
@nosajhpled
nosajhpled / PHP : Return the Name of the Month by Numerical Value
Created December 4, 2022 14:59
PHP : Return the Name of the Month by Numerical Value
This function will return the name of the month by passing the month's number. (Ex: 1 will return January).
///Return the name of the month /// $month : the number of the month (1 - Jan) // $long (bool) : true for long name; false for short name /* Example : NumToMonth(1,true) will return January NumToMonth(1,false) will return Jan */ function NumToMonth($month,$long) { $rtn =""; $month_names = array(1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec", 13 => "January", 14 => "February", 15 => "March", 16 => "April", 17 => "May", 18 => "June", 19 => "July", 20 => "August", 21 => "September", 22 => "October", 23 => "November", 24 => "December"); if ($month >= 1 and $month <= 24) { // multiply $month by 1 to always have a number // 03 will become 3
@nosajhpled
nosajhpled / This handy line of PHP code will retun the script name only without the full path
Created December 4, 2022 14:59
This handy line of PHP code will retun the script name only without the full path
preg_split('/\//', $_SERVER['SCRIPT_NAME'])[count(preg_split('/\//', $_SERVER['SCRIPT_NAME']))-1]
Example:
http:\\localhost\test.php
Would become:
test.php
@nosajhpled
nosajhpled / FoxPro 7.0+ - Extract filename from a full path
Created December 4, 2022 14:58
FoxPro 7.0+ - Extract filename from a full path
Here is an easy way to extract the filename from a full path in Foxpro:
frow = ALINES(fname,fullpath,1,"\")
filename = fname[frow]
So if fullpath = c:\test.txt
then
filename will be test.txt.
@nosajhpled
nosajhpled / gist:69e293c977ed2f16db6d459c57035113
Created December 4, 2022 14:57
PHP : Alternating Row Color in a HTML Table
.alt { background-color:#F0F2FF; }
echo '<tr '.(!isset($alt) ? $alt = 0 : $alt++ % 2 == 0 ? 'class="alt"' : '').'>';
#PHP
This code will allow you to send a raw MongoDB query to the server and return back a record set. This will allow you to write queries as if you are writing them for the console.
// Connect to the MongoDB Database/Collection
// Enter your Database name and Collection Name
MongoCollection<BsonDocument> myMongoDB = new MongoClient("mongodb://localhost").GetServer().GetDatabase("Insert Database Name").GetCollection<BsonDocument>("Insert Collection Name");
// Write your query as you would in the MongoDB console
var query = "{somefield : \"some value\"}"; // escape your double quotes inside the string
tr:nth-child(even){
color:blue;
}
tr:nth-child(odd){
color:red;
}
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT SELECT ON database.* TO 'username'@'%';
GRANT INSERT ON database.* TO 'username'@'%';
GRANT UPDATE ON database.* TO 'username'@'%';
Run Tests:
clear;./vendor/bin/phpunit
Create a new test:
php artisan make:test {Class}Test
@nosajhpled
nosajhpled / BasicVueStructure
Created June 12, 2019 12:56
Basic Vue Structure
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script type="text/javascript">
var formValidation = new Vue({
el:'',
data:{
},
methods:{
methodName: function (){
}