Skip to content

Instantly share code, notes, and snippets.

View sworup's full-sized avatar
🦖
Normal

Sworup Shakya sworup

🦖
Normal
View GitHub Profile
@sworup
sworup / Datepicker Initializer (PHP) (jQuery) (jQuery UI) (Datepicker).php
Last active May 4, 2016 05:11
Datepicker Initializer (PHP) (jQuery) (jQuery UI) (Datepicker)
<?php
function createDateRangeArray($strDateFrom,$strDateTo)
{
// takes two dates formatted as YYYY-MM-DD and creates an
// inclusive array of the dates between the from and to dates.
// could test validity of dates here but I'm already doing
// that in the main script
$aryRange=array();
@sworup
sworup / make directory if doesn't exist.php
Last active May 4, 2016 05:10
Make directory if does not exist (PHP)
<?php
if (!file_exists('path/to/directory')) {
mkdir('path/to/directory', 0777, true);
}
@sworup
sworup / wp01.php
Last active May 4, 2016 05:13
Wordkpress: Add Custom Image Sizes to Media Uploader. https://pippinsplugins.com/add-custom-image-sizes-to-media-uploader/
<?php
function pw_add_image_sizes() {
add_image_size( 'pw-thumb', 300, 100, true );
add_image_size( 'pw-large', 600, 300, true );
}
add_action( 'init', 'pw_add_image_sizes' );
function pw_show_image_sizes($sizes) {
$sizes['pw-thumb'] = __( 'Custom Thumb', 'pippin' );
$sizes['pw-large'] = __( 'Custom Large', 'pippin' );
@sworup
sworup / CustomValidation.php
Created May 18, 2016 04:43
Custom validation problem. The 'ip' never gets included in the request input object before it gets validated, hence the validation fails.
<?php
namespace App\Extentions;
use DB;
use Log;
use Illuminate\Validation\Validator;
class CustomValidation extends Validator {
@sworup
sworup / laravel-validation-error.js
Last active July 9, 2021 13:04
Handling of Laravel validation message when pulled through Ajax request
error: function (request) {
// Validation error would return 422 header
if (request.status == 422) {
// Parser the json response expected
var $errors = $.parseJSON(request.responseText);
// Bootstrap alert scafolding for error
var errorsHtml = '<div class="alert alert-danger alert-dismissible"><button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button><h4><i class="icon fa fa-times"></i>Opps! Seems like you didn\'t fill the form properly...</h4><ul>';
// The root nodes are field names, with an array of error messages
$.each( $errors, function( key, value ) {
// We loop through the error to see if there are multiple error associated with the field
@sworup
sworup / laravel-add-after-in-request.php
Created July 31, 2016 07:00
Laravel- Add after hook in request file. Reference: https://goo.gl/8BhhCB
<?php
/**
* Get the validator instance for the request and
* add attach callbacks to be run after validation
* is completed.
*
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function getValidatorInstance()
{
@sworup
sworup / AppServiceProvider.php
Created December 9, 2016 06:13
Load config files from a directory
<?php
namespace Sworup\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Finder\Finder;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
}
@sworup
sworup / npm-debug.log
Created December 9, 2016 10:05
Error while doing npm install in mac osx vagrant build with Laravel
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated [email protected]: use uuid module instead
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN prefer global [email protected] should be installed with -g
npm WARN prefer global [email protected] should be installed with -g
npm WARN prefer global [email protected] should be installed with -g
@sworup
sworup / sql_log.php
Created December 27, 2016 07:38
Adding a DB Listener to log the sql query in log file
<?php
use Illuminate\Support\Facades\Log;
\DB::listen(function($sql, $bindings, $time) {
Log::info($sql);
Log::info($bindings);
Log::info($time);
});
// Your query goes after this
@sworup
sworup / w1250_to_utf8_converter.php
Created March 1, 2017 10:08
Foreign Charater to UTF8 converter
<?php
function w1250_to_utf8($text) {
// map based on:
// http://konfiguracja.c0.pl/iso02vscp1250en.html
// http://konfiguracja.c0.pl/webpl/index_en.html#examp
// http://www.htmlentities.com/html/entities/
$map = array(
chr(0x8A) => chr(0xA9),
chr(0x8C) => chr(0xA6),