Skip to content

Instantly share code, notes, and snippets.

View mikehins's full-sized avatar

Mike Hins mikehins

  • Trinary
  • Mont-Tremblant
  • 20:56 (UTC -04:00)
View GitHub Profile
@mikehins
mikehins / beforeunload.js
Last active August 29, 2015 14:05
Alert user to save before unload
$(document).ready(function() {
// ----------------------------
// Show message if data have been modified without saving first
// ----------------------------
var CHANGED = false;
window.onbeforeunload = function() {
return (CHANGED == true ? "Leaving Page with unsaved changes" : null);
}
// ----------------------------
@mikehins
mikehins / gist:6465337
Last active December 22, 2015 11:28
Jquery Utils snippets
// console.log
$.fn.extend({debug: function(msg){
return $(document).each(function() {
if (window.console && window.console.log) window.console.log(msg);
});
}
});
// minified
(function($){$.extend({log:function(e){return $(document).each(function(){if(window.console&&window.console.log)window.console.log(e)})}})}(jQuery));
@mikehins
mikehins / config
Created October 19, 2013 14:38
VHOST
windows/system32/drivers/etc/hosts
127.0.0.1 www.mysite.dev
wamp\bin\apache\apache2.4.2\conf\httpd.conf
Listen 80
Listen 8080
wamp\bin\apache\apache2.4.2\conf\extra\httpd-vhosts.conf\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot E:/Wamp/www/mysite
@mikehins
mikehins / json_replace.php
Last active December 8, 2016 12:52
Replace value inside a json string with regex
function json_replace($key, $value, $json_string)
{
return preg_replace('/"' . $key . '":".*?"/', '"' . $key . '":"' . $value . '"', $json_string);
}
@mikehins
mikehins / ajax.php
Last active December 21, 2016 10:25
Ajax call boiler plate for jQuery
var AJAX = {
post: function (u, d, dt, cb) {
dt = typeof dt !== 'undefined' ? dt : 'json';
return $.ajax({
url: u,
data: d,
type: 'POST',
dataType: dt
});
@mikehins
mikehins / gist:60d3eab6113e6f61b62cd4c09e6d3f1c
Created April 21, 2017 01:46
create_translations_table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTranslationsTable extends Migration
{
/**
* Run the migrations.

Keybase proof

I hereby claim:

  • I am mikehins on github.
  • I am mikehins (https://keybase.io/mikehins) on keybase.
  • I have a public key ASCW6Wc-gQe9xWBpZGeEprTkF8Lj2ktKVVlWbzrQw-cZogo

To claim this, I am signing this object:

@mikehins
mikehins / Kernel.md
Last active May 16, 2017 14:27
Laravel Scheduler Command

Je dois migrer / transformer la bd de prod vers celle de staging à chaque soir avec le scheduler.

j'ai un peux plus que 100 000 records à transformer par table, y a une table avec au dessus de 250 000 records en f*** json qui faut que je sépare en plusieurs autres relations

$schedule->command('acme:command1')->timezone('America/Toronto')->dailyAt('20:00')->after(function(){
  $this->call('acme:command2'); 
  $this->call('acme:command3'); 
  $this->call('acme:command4');
@mikehins
mikehins / whereJson.php
Last active November 23, 2018 18:47
Query json by key with laravel
public function whereJSON($key, $value)
{
$fields = explode('.', $key);
if (count($fields) !== 2) {
die('Please use this format field_name.key to query JSON');
}
$fieldname = $fields[0];
return $this->whereRaw($fieldname . ' REGEXP \'"' . $fields[1] . '":"([^"]*)' . $value . '([^"]*)"\'')->get()
->map(function ($item) use ($fieldname) {
@mikehins
mikehins / multi_array_unique.php
Last active March 4, 2019 16:20
Make a multidimensionnal array unique by key
$unique = array_intersect_key($array, array_unique(array_column($array, 'email')));