Skip to content

Instantly share code, notes, and snippets.

View ste2425's full-sized avatar

Stephen Cooper ste2425

View GitHub Profile
@ste2425
ste2425 / click.js
Created February 19, 2016 10:47
Click handler that will not fire if element is disabled. (anchor tags)
/*
Will call your click handler if the element is not disabled.
Usefull for legacy apps where elements such as anchor tags are used.
As these do not respect the disabled attribute.
Does not matter how element is disabled, angular, jQuery native or even devTools.
Should strongly consider using it outside the `ng` namesapce.
*/
@ste2425
ste2425 / uart.c
Created May 17, 2016 19:09
flawed uart for pic. It resets.
#define _XTAL_FREQ 4000000
#include <pic16f688.h>
#include <xc.h>
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
@ste2425
ste2425 / group.js
Created July 15, 2016 15:18
Simple JavaScript Group
"use strict";
let group = (arr, by) => arr.reduce((prev, cur) => {
let val = isFunction(by) ? by(cur) : cur[by];
prev.hasOwnProperty(val) ? prev[val].push(cur) : prev[val] = [cur];
return prev;
}, {}),
isFunction = (x) => Object.prototype.toString.call(x) === "[object Function]";
module.exports = () => ({group, isFunction});
@ste2425
ste2425 / _grid.scss
Created July 20, 2016 14:35
response grid layout
/*
Variables:
$screen-size-small
$screen-size-medium
$screen-size-large
$grid-small-screen-width
$grid-medium-screen-width
$grid-large-screen-width
@ste2425
ste2425 / vendorPrefix.scss
Created July 21, 2016 09:03
Vender prefix utility
@mixin vendorPrefix($prop, $val) {
-webkit-#{$prop}: $val;
-moz-#{$prop}: $val;
-ms-#{$prop}: $val;
-o-#{$prop}: $val;
#{$prop}: $val;
}
/*
Use:
@ste2425
ste2425 / promisifyExample.js
Created November 2, 2016 16:08
Little promisify helper
let promisify = (fn) => (...args) =>
new Promise((rCB, eCB) =>
fn(...args, (e, r) => {
if (e)
eCB(e);
else
rCB(r);
}));
promisify(sass.render({
@ste2425
ste2425 / disableValidation.js
Created December 2, 2016 14:06
Prevent validation on disabled and hidden elements
.directive('ignoreDisabled', ['$exceptionHandler', ($exceptionHandler) => {
return {
restrict: 'A',
require: 'ngModel',
link: ($scope, elem, attr, ctrl) => {
if (!attr.hasOwnProperty('ngDisabled')) {
$exceptionHandler(new ReferenceError('Attempt to use ignoreDisabled on element without ngDisabled.'));
} else {
$scope.$watch(attr.ngDisabled, (val, oldVal) => {
if (val === true && val !== oldVal) {
@ste2425
ste2425 / store.js
Last active May 12, 2017 14:27
Electron persistent store
'use stirct';
const electron = require('electron'),
userDataPath = (electron.app || electron.remote.app).getPath('userData'),
path = require('path'),
fs = require('fs');
class Store {
constructor(configName = '') {
// Probably want to implement error handling
@ste2425
ste2425 / .gitignore
Created July 23, 2017 17:46 — forked from iffy/.gitignore
Example using electron-updater with `generic` provider.
node_modules
dist/
yarn.lock
wwwroot
@ste2425
ste2425 / enumerator.js
Last active August 1, 2018 07:34
Close Contacts Enumerator polly-fill
if (!window.Enumerator) {
window.Enumerator = function (c) {
this._c = Array.from(c);
this._index = 0;
}
window.Enumerator.prototype.atEnd = function () {
return this._index >= this._c.length - 1;
}