Skip to content

Instantly share code, notes, and snippets.

@jamesmosier
jamesmosier / headingStyles.js
Created Jan 31, 2020
Get all heading styles on a page
View headingStyles.js
var headings = ['h1','h2','h3', 'h4', 'h5','h6'];
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
headings.map(heading => {
return {
[heading]: [...document.querySelectorAll(heading)].map(item => window.getComputedStyle(item).fontSize).filter(onlyUnique)
};
@jamesmosier
jamesmosier / PriceSlider.jsx
Last active Mar 20, 2019
Slider using useImperativeHandle hook
View PriceSlider.jsx
import React, { useRef } from 'react';
import Slider from './Slider';
import useSlider from './useSlider';
const MIN_VALUE = 0;
const MAX_VALUE = 500;
function PriceSlider() {
const sliderRef = useRef(null);
@jamesmosier
jamesmosier / locations.json
Created Jul 26, 2018
Locations test with duplicate coords
View locations.json
{
"count": 10785236,
"photos": [{
"photo_id": 555,
"photo_title": "222 Atardecer en Embalse",
"photo_url": "http://www.panoramio.com/photo/27932",
"photo_file_url": "http://mw2.google.com/mw-panoramio/photos/medium/27932.jpg",
"longitude": -64.404945,
"latitude": -32.202924,
"width": 500,
@jamesmosier
jamesmosier / android-google-play-api-subscriptions.js
Created Mar 27, 2018
Example, using Node, on how to get user subscriptions using the Google Play Developer API (with androidpublisher role)
View android-google-play-api-subscriptions.js
const { google } = require("googleapis");
const publisher = google.androidpublisher("v2");
const OAuth2 = google.auth.OAuth2();
const SERVICE_ACCOUNT_EMAIL = "some_google_acccount@gmail.com";
const SERVICE_ACCOUNT_KEY_FILE = require("./path/to/credentials.json");
const jwtClient = new google.auth.JWT(
SERVICE_ACCOUNT_KEY_FILE.client_email,
View webpack.config.js
'use strict';
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const resolve = path.resolve;
const rootDir = resolve(__dirname);
const dist = resolve(rootDir, 'appname/secured_assets');
const assetIndex = resolve(rootDir, 'src/app');
@jamesmosier
jamesmosier / babel.js
Last active Feb 18, 2016
babel js grunt task
View babel.js
//npm install --save-dev grunt-babel babel-preset-es2015
'use strict';
module.exports = {
options: {
sourceMap: true,
presets: ['es2015']
},
dist: {
files: [{
@jamesmosier
jamesmosier / Angular-Directive-jQuery-Plugin
Created Oct 28, 2014
AngularJS Directive for jQuery plugin that fires on partial load
View Angular-Directive-jQuery-Plugin
//To use this: <div tfinder-map="{queryLimit: 3}"></div>
angular.module('myApp.directives', []).
directive('tfinderMap', function($timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe("tfinderMap", function(value) {
if (value) {
@jamesmosier
jamesmosier / Null-Empty-Int
Created Oct 28, 2014
Check for null or empty int
View Null-Empty-Int
//To check for null int (if int is marked as nullable)
if (request.Tickets.Any(x => x.EventId == default(int?))) {}
//Otherwise to just check for "no" eventId which is zero
if (request.Tickets.Any(x => x.EventId == 0)) {}
View breakpoints.css
// Mobile First
@media screen and (min-width: 321px) { // iPhone landscape
}
@media screen and (min-width: 481px) { // iPad portrait
}