Skip to content

Instantly share code, notes, and snippets.

@jgornick
jgornick / ping-test.sh
Created March 4, 2016 02:40
Shell (Bash): Ping test and log timestamps when ping fails.
#!/bin/bash
truncate /tmp/ping.log -s 0
while true; do
if ! ping -I ppp0 -s 8 -c 1 8.8.8.8 &> /dev/null; then
date --rfc-3339=ns | tee -a /tmp/ping.log &> /dev/null
fi
sleep 30
done
@jgornick
jgornick / jquery.maskInput.js
Last active August 29, 2015 14:25
jQuery Plugin: $.maskInput - Converts password fields into a field that will show content on focus and hide on blur.
;(function($, window, document, undefined) {
'use strict';
var
pluginName = 'maskInput',
defaults = {
// The masked character when the field is blurred.
character: '%u25CF',
// Convert the element from password to text to bypass browser password persistence.
bypassPassword: false
@jgornick
jgornick / ansible.yml
Created May 19, 2015 12:49
Ansible: Remove All Files Except
---
- name: Capture files in path and register
shell: >
ls -1 /path/to/files
register: files
- name: Remove files except specified
file:
path: "/path/to/files/{{ item }}"
state: absent
@jgornick
jgornick / require.js
Created May 9, 2015 17:46
Mongoose/MongoDB: Index Array of Embedded Documents
import timestamp from 'mongoose-timestamp';
export default function(mongoose) {
let
Schema = mongoose.Schema;
/**
* @type {Schema}
*/
let RequireSchema = new Schema({
@jgornick
jgornick / open-all-projects.sh
Created April 13, 2015 14:20
Sublime Text: Open All Projects
find . -type f -name "*sublime-project" -exec subl --project {} \;
@jgornick
jgornick / gulp-convert-stream.js
Last active August 29, 2015 14:17
Gulp Convert to Stream
import gulp from 'gulp';
import through from 'through2';
gulp
.src('/tmp/file.txt')
.pipe(through.obj(function(file, encoding, done) {
if (file.isBuffer()) {
this.push(file.contents);
done();
}
@jgornick
jgornick / static-class.js
Last active August 29, 2015 14:17
ES6 Class Static Access
class Foo {
static getType() {
return 'foo';
}
getType() {
return this.constructor.getType();
}
constructor() {
@jgornick
jgornick / 00.js
Last active August 29, 2015 14:16
fast-csv Stream Error Issues
// With this example, the error that is thrown outside of the stream is actually caught inside the stream.on('error') handler.
var
fs = require('fs'),
csv = require('fast-csv');
function throwError() {
throw new Error('implicit error');
}
@jgornick
jgornick / 00-marionette-dashboard.md
Last active August 29, 2015 14:15
Marionette: Dashboard Framework
@jgornick
jgornick / regex.txt
Last active November 5, 2021 19:13
RegEx: US Medicare Number Validate and Match
# Accepted formats are 0-3 alpha, 9 digits, and 1-3 alpha-numeric with or without spaces and dashes:
# * AAA-000-00-0000-AAA
#
# http://survivinghealthinsurance.com/2010/medicare-id-numbers-suffixes-and-prefixes/
/^([a-z]{0,3})[-\s]?(\d{3})[-\s]?(\d{2})[-\s]?(\d{4})[-\s]?([0-9a-z]{1,3})$/i