Skip to content

Instantly share code, notes, and snippets.

View nathanlogan's full-sized avatar

Nathan Logan nathanlogan

View GitHub Profile
@nathanlogan
nathanlogan / DateUtils.ts
Created January 27, 2022 21:41
Convert date string to user's locale
export const formatDateAsDefaultLocale = (incomingDate: string | Date, options?: Intl.DateTimeFormatOptions): string => {
const defaultOptions = { day: 'numeric', month: 'short', year: 'numeric' }
const date = new Date(incomingDate)
return date.toString() !== "Invalid Date" ? date.toLocaleString('default', options || defaultOptions) : '';
}
@nathanlogan
nathanlogan / package.json
Last active June 13, 2017 20:00
An npm one-liner OSX script for npm linking all components in a subdirectory
{
"name": "",
"version": "",
"description": "",
"repository": {},
"scripts": {
"link-one:osx": "cd src/components/ && select fname in */; do (cd $fname && npm link) && break; done && cd ../..",
"link-all:osx": "cd src/components/ && for fname in */; do (cd $fname && npm link); done && cd ../.."
},
"dependencies": {},
@nathanlogan
nathanlogan / component.js
Created November 15, 2016 19:29
Emulate URL anchor page scroll functionality in a React component
import React, { Component } from 'react'
class MyTopLevelComponent extends Component {
componentDidMount () {
this.scrollToHashId()
}
componentDidUpdate () {
this.scrollToHashId()
}
@nathanlogan
nathanlogan / gist:18e6c0068d826506df715552197b7f5b
Created November 3, 2016 23:23
Bookmarklet: populate and submit a known form
When you don't have access to the source code of a form, you may be stuck in a position where autofill doesn't work and you are doing a lot of repetitive entry. That's where this script comes in. Now you click a button and the form autofills with (static) values of your choice and immediately submits. Some forms may not work very well with this approach (like ones where the fields are dynamic, don't have distinguishable attribute identifiers, etc.), but it works well for my current use case. YMMV.
The code (without preview, due to good security restrictions):
<a href="javascript:!(function (doc) { doc.getElementById('HwPxTokenOneField').value = 'Doe'; doc.getElementById('HwPxDOBMonthField2').value = '01'; doc.getElementById('HwPxDOBDayField2').value = '17'; doc.getElementById('HwPxDOBYearField2').value = '1971'; doc.getElementById('HwPxLoginButton').click()})(window.document);">eSDP Login</a>
The example and demo (use this to actually add the bookmarklet):
https://jsfiddle.net/nathanlogan/b3znt9q2/
@nathanlogan
nathanlogan / Bookmarklet: test CSS build quality with visual design export bg image
Last active August 29, 2015 14:16
In short: visually "diff" your image with your UI. In "not so short": this script takes a user-specified image path as input (any path that works as a CSS background image will do), and sets that as the centered background image of the <html> element. It also applies a 50% opacity to the <body> element, so the background can "shine through". Its…
<a href="javascript:!function(e){var t=prompt('Please enter a URL for the background image to be applied to the <html> element:','designExport.jpg');null!=t?(e.documentElement.style.background='url('+t+') no-repeat center top',e.body.style.opacity='.5'):e.body.style.opacity='1'}(window.document);">BG IMG CHCKR</a>
require "rubygems"
require "json"
require "net/http"
require "uri"
puts ""
puts "Enter your Twitter username:"
username = gets.chomp