Skip to content

Instantly share code, notes, and snippets.

View pardamike's full-sized avatar
💻
Coding

Mike Parda pardamike

💻
Coding
  • Virginia
  • 19:22 (UTC -04:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am pardamike on github.
  • I am mikeparda (https://keybase.io/mikeparda) on keybase.
  • I have a public key ASB74LKdJGSYESW0GkMMThTmkALl8wUiadicy-XJkRiOWgo

To claim this, I am signing this object:

@pardamike
pardamike / number-only.directive.ts
Last active October 25, 2021 14:37
Angular 6 Directive to allow only positive integers in an input
// *** NOTE: This is only allowing positive integers, adjust the regex to suit your needs
// Stackblitz (w/ Angular Material): https://stackblitz.com/edit/angular-8fsecv?file=app%2Fnumber-only.directive.ts
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[numberOnly]'
})
export class NumberOnlyDirective {
// Only want positive integers
<button type="button" id="clickMe1">Click me 1</button>
<button type="button" id="clickMe2">Click me 2</button>
<script>
(function () {
// No customization
var fbModal = $.fn.bootstrapFeedback({
getOptionsUrl: 'https://some.api/getOptions',
;(function ($) {
$.fn.bootstrapFeedback = function (config) { // Add object to jQuery's functions
var bsfb = {
// Settings variables
targetElementId: 'showFeedbackForm',
getOptionsUrl: false,
sendFeedbackUrl: false,
styles: {
submitBtnClasses: 'btn btn-primary',
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Feedback</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/b430732d7c.js"></script>
</head>
<body>
var Feedback = {
// Run will initialize all of these functions and event handlers
// And they have the settings variable we passed in to work with
run: function (settings) {
// Click action for
$(document).on('click', '#showFeedbackForm', function () {
getOptions().then(function (ajaxRes) {
// Once options are loaded, build the select list
// Using fake data here, 'options' would normally be from ajaxRes
var options = [
/* Commonly Misused jQuery AJAX Settings: */
// As of jQuery 2.x
$.ajax({
accept: 'json', // Tells the server the format the client accepts back
dataType: 'json', // When set to 'json', will pre-parse the JSON for you
error: function () {
console.log("Oh no we got a 500!"); // Callback for server errors and timeouts/bad responses
},
success: function () {
/* If you are able to load your scripts at the END of your body
* (right before the closing </body> tag), you can use a self invoking
* function, which is nothing more than a function that executes
* as soon as the browser reads it.
*/
(function () {
// Code to be immediatly ran goes in here
)();
// Your </body> will be the only HTML that will be after this function, all other HTML must come before it
@pardamike
pardamike / 2-1.js
Last active December 1, 2017 06:46
/* Attaching event listners with jQuery method 1: */
$('#someElement').click(function (event) {
// Do something with the event
});
/* Attaching event listners with jQuery method 2: */
$(document).on('click', '#someElement', function (event) {
// Do something with the event
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
</head>
<style>
/* Styles in here */