Skip to content

Instantly share code, notes, and snippets.

View dniccum's full-sized avatar

Doug Niccum dniccum

View GitHub Profile
@dniccum
dniccum / add-typeform.js
Created July 27, 2021 14:06
Dynamically appends a Typeform element to a page within a method/function
const body = document.getElementsByTagName('body')[0];
const tag = document.createElement('a');
const formId = '#####'; // Change this to your specific form ID
tag.setAttribute('class', 'typeform-share button');
tag.setAttribute('href', `https://form.typeform.com/to/${formId}?typeform-medium=embed-snippet`);
tag.setAttribute('data-mode', 'popover');
tag.setAttribute('data-open', 'time');
tag.setAttribute('data-open-value', '1000');
tag.setAttribute('target', '_blank');
@dniccum
dniccum / SecureInput.js
Created October 4, 2018 15:13
A Vue.JS directive that toggles the input type from text to password on blur; creating a secure input.
import Vue from 'vue';
Vue.directive('secure-input', {
inserted(el) {
el.type = 'password';
},
bind(el) {
el.addEventListener('focus', () => {
el.type = 'text'
});
@dniccum
dniccum / FizzBuzz.py
Created February 24, 2018 21:24
A basic Python application called FizzBuzz
for x in range(1, 101):
if x % 3 == 0 and x % 5 != 0:
print "Fizz"
elif x % 5 == 0 and x % 3 != 0:
print "Buzz"
elif x % 5 == 0 and x % 3 == 0:
print "FizzBuzz"
else:
print x
@dniccum
dniccum / ErrorService.js
Last active February 29, 2016 23:03
A custom error reporting workflow for SailsJS that uses AngularJS and the NodeJS package sails-hook-validation
module.exports = {
ParseUserErrors: function(errors) {
var validationErrors = [];
for (var key in errors) {
if (errors.hasOwnProperty(key)) {
for (var item in errors[key]) {
if (errors[key][item].rule !== "string") {
validationErrors.push(errors[key][item].message);
}
@dniccum
dniccum / jQuery Counter
Last active August 29, 2015 14:16
A basic jQuery/Javascript counter to counts up to a certain number within a certain time period.
// target: The jQuery/Javascript element that you want the function to affect
// targetNumber: The max number you want the counter to get to
// type: Type of units the function outputs; can be modifed
// currentNumber: The number you would like to start from; leave undefined to start from zero
function countUp(target, targetNumber, type, currentNumber) {
var integer,
interval = (3 / targetNumber) * 1000; // 3 is the amount of time to give the counter to reach its desired amount
if (currentNumber === undefined) {
@dniccum
dniccum / _variables.scss
Last active August 29, 2015 14:00
This is my basic boilerplate of SCSS mixins that I have been compiling
// MIXINS
@mixin shadow($color: #B8B8B8) {
-webkit-box-shadow: 0 0 10px 2px $color;
box-shadow: 0 0 10px 2px $color;
}
@mixin gradient($color1, $color2) {
background: $color1;
background: -moz-linear-gradient(top, $color1 0%, $color2 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$color1), color-stop(100%,$color2));