Skip to content

Instantly share code, notes, and snippets.

View mjpitz's full-sized avatar
🏳️‍🌈
out and proud

Mya mjpitz

🏳️‍🌈
out and proud
View GitHub Profile
@mjpitz
mjpitz / ResourceController.java
Created February 6, 2014 17:19
Fully stubbed out REST controller for Spring MVC
package com.example.controllers;
import com.example.models.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@mjpitz
mjpitz / simpleservers.sh
Last active August 29, 2015 13:56
Simple servers for command line. Serve html or php scripts with the following commands.
function servephp() {
local port="${1:-8080}"
open "http://localhost:${port}"
php -S localhost:$port
}
function serve() {
local port="${1:-8000}"
open "http://localhost:${port}"
python -m SimpleHTTPServer "$port"
@mjpitz
mjpitz / GetterSetterVerifier.java
Last active March 7, 2023 17:32
A class that uses reflection to automate the testing of getters and setters.
import com.google.common.base.Defaults;
import com.google.common.collect.Sets;
import javax.annotation.Nonnull;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;
@mjpitz
mjpitz / protobuf-closure.sh
Created September 25, 2014 07:49
Easily create a protobuf plugin for closure objects
#!/bin/bash
############################################################
# First, you must build the library files for the protobuf
# tool. In order to do this, follow the steps below in the
# source directory for protobuf.
#
# 1. ./autogen.sh
# 2. ./configure
# 3. make
#
@mjpitz
mjpitz / di.js
Last active August 29, 2015 14:11
Simple dependency injection using reflection
(function($, undefined) {
var dependencies = {},
instances = {};
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function stripComments(functionString) {
return functionString.replace(STRIP_COMMENTS, '');
}
var FN_NEW_LINE_REPLACE = /[\s\r\n]+/;
@mjpitz
mjpitz / dataUtil.js
Last active June 29, 2018 15:51
Useful data analysis methods for NodeJS.
/**
* @fileoverview Useful data operations for manipulating large sets of data.
*
* I initially wrote this utility for handling the idea-frameworks
* documentation generator where I would group and regroup data into more
* manageable chunks.
*/
var util = require('util');
@mjpitz
mjpitz / StickyGithubHeader.js
Last active November 19, 2015 13:49
Make the project banner on a repository page sticky as you scroll down (new ui only)
(function() {
var $ = function(str) {
return document.querySelector(str);
};
var win = window;
var doc = document.documentElement;
var mast = $('#js-repo-pjax-container .pagehead');
var mastTop = mast.offsetTop;
var adjustedMargin = mast.offsetHeight;
@mjpitz
mjpitz / StickyGithubHeader Bookmarklet
Created November 19, 2015 13:58
Same as the js file, but as a bookmarklet
javascript:(function() {var $ = function(str) {return document.querySelector(str);};var win = window;var doc = document.documentElement;var mast = $('#js-repo-pjax-container .pagehead');var mastTop = mast.offsetTop;var adjustedMargin = mast.offsetHeight;var currentMastAttributes = mast.getAttribute('style');var newMastAttributes = [currentMastAttributes,'position: fixed;','z-index: 10;','top: 0;','left: 0;','right: 0;'].join('');var content = $('#js-repo-pjax-container .repo-container');var currentContentAttributes = content.getAttribute('style');var newContentAttributes = [currentContentAttributes,'margin-top: ' + adjustedMargin + 'px;'].join('');var toggle = false;document.addEventListener('scroll', function() {var scrollTop = (win.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);if (scrollTop > mastTop) {content.setAttribute('style', newContentAttributes);mast.setAttribute('style', newMastAttributes);toggle = true;setTimeout(function() {toggle = false}, 100);} else if (!toggle) {content.setAttribute('
@mjpitz
mjpitz / FluentXhr.js
Created January 26, 2016 04:03
Kinda a cool idea where I applied the Fluent Interface design pattern at the XmlHttpRequest object with some additional helpers.
// provide our own undefined
const undefined = void(0);
// provide an extend method
Object.extend = function(protoTo, ...protoFroms) {
protoFroms.forEach(function(protoFrom) {
Object.keys(protoFrom).forEach(function(key) {
if (protoTo[key] === undefined)
protoTo[key] = protoFrom[key];
});
@mjpitz
mjpitz / gremlin.d.ts
Created June 27, 2018 03:51
Typescript definition for apache tinkerpop's gremlin-javascript library. Makes for easy use with Typescript language.
declare module "gremlin" {
export namespace driver {
import TraversalStrategy = process.TraversalStrategy;
import Traversal = process.Traversal;
import Bytecode = process.Bytecode;
import GraphSONReader = structure.io.GraphSONReader;
import GraphSONWriter = structure.io.GraphSONWriter;
export class RemoteConnection {
constructor(url: string);