Skip to content

Instantly share code, notes, and snippets.

View MohamedLamineAllal's full-sized avatar

Mohamed Lamine Allal MohamedLamineAllal

View GitHub Profile
@MohamedLamineAllal
MohamedLamineAllal / LaravelCarbonTimeDiffAndEloquent.php
Created November 27, 2018 13:25
how to do time comparison (with periods, diff ..) IN laravel using Carbon
<?php
$articles = Article::where("created_at",">", Carbon::now()->subMonths(6))->get();
@MohamedLamineAllal
MohamedLamineAllal / TIMESTAMPDIFF_where.sql
Created November 27, 2018 13:23
Using TIMESTAMPDIFF to get something that is a certain period old (with a where statement)
SELECT *,
TIMESTAMPDIFF(DAY,created_at, CURRENT_TIMESTAMP()) -- just to check it's working
FROM RentCar.companies
where TIMESTAMPDIFF(DAY, created_at, CURRENT_TIMESTAMP()) < 5;
@MohamedLamineAllal
MohamedLamineAllal / TIMESTAMPDIFF_where.sql
Created November 27, 2018 13:23
Using TIMESTAMPDIFF to get something that is a certain period old (with a where statement)
SELECT *,
TIMESTAMPDIFF(DAY,created_at, CURRENT_TIMESTAMP()) -- just to check it's working
FROM RentCar.companies
where TIMESTAMPDIFF(DAY, created_at, CURRENT_TIMESTAMP()) < 5;
@MohamedLamineAllal
MohamedLamineAllal / js_and_jquerySelectBoxManipulation_boiler.js
Created November 27, 2018 09:56
Boiler plate and example for jquery and pure js manipulation of select boxes
//example using select2 pluging (don't forget .trigger('change.select2'))
phoneCodeSelect.on('change', function () {
let countryName = $(this).find('option:selected').eq(0).text().replace(/\(.*\)/, '').trim().toUpperCase();
countrySelect.val(countryName).trigger('change.select2');;
// countrySelect.find('option:selected').prop('selected', false);
// countrySelect.find('option[value=' + $(this).find('option:selected').eq(0).text().replace(/\(.*\)/, '').trim().toUpperCase() + ']').prop('selected', true);
console.log('ssssssssssssssssssssssssssssssssssss');
console.log($(this).find('option:selected').eq(0).text().replace(/\(.*\)/, '').trim().toUpperCase());
console.log(countrySelect);
@MohamedLamineAllal
MohamedLamineAllal / typehead_bloodHound_automaticCHangementOfDataset.js
Created November 27, 2018 09:51
TypeHead and BloodHound automatic dataset update example
axios.get('/json/countries')
.then(function (resp) {
countriesCities = resp.data;
// alert(JSON.stringify(countriesCities['Afghanistan']));
cc_bloodHound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
reinitialize: true,
locale: null
@MohamedLamineAllal
MohamedLamineAllal / ucwords.js
Created November 27, 2018 09:49
ucwords in javascriopt (uper case Words (only first character un upper and the rest lower of each word)
function ucwords(str) {
str = str.toLowerCase().replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g, function (replace_latter) {
return replace_latter.toUpperCase();
}); //Can use also /\b[a-z]/g
return str; //First letter capital in each word
}
@MohamedLamineAllal
MohamedLamineAllal / laravelServeJavascriptFilesFromRoutes.php
Created November 22, 2018 15:48
Laravel Serve javascript files through a route
<?php
Route::group(['prefix' => 'js'], function () {
Route::get('filterizr', function () {
return response()->file(base_path('node_modules/filterizr/dist/jquery.filterizr.min.js'), [
'Content-Type' => 'application/javascript'
]);
})->name('js.filterizr');
});
@MohamedLamineAllal
MohamedLamineAllal / mysql_boilerplate.sql
Last active December 15, 2018 15:32
Mysql boilerplate
-- safe mode update , ....
-- update
SET SQL_SAFE_UPDATES = 0;
-- your nice code here
SET SQL_SAFE_UPDATES = 1;
-- Set a column all record values to a one value
SET SQL_SAFE_UPDATES = 0;
@MohamedLamineAllal
MohamedLamineAllal / dropzonejsBoiler.js
Created November 21, 2018 11:04
Dropezonejs complete example (thumbnail preloading, sending a form a long, or form alone, going arround add to dropzone quirk)
var lastLogoUrl = '{{route('storage.companies.logo', ['file' => basename($cmpny->logo)])}}';
{{-- var isLogoUpdated = false; --}}
var updatedData = null;
var oldData = null;
var form = null;
var dataToSend = null;
@MohamedLamineAllal
MohamedLamineAllal / formArrayToObj.js
Last active November 19, 2018 00:04
turn array data from serializeArray() jquery method to object format
function formArrayToObject(formArray) {//serialize data function
var returnArray = {};
for (var i = 0; i < formArray.length; i++){
returnArray[formArray[i]['name']] = formArray[i]['value'];
}
return returnArray;
}