Skip to content

Instantly share code, notes, and snippets.

@MrJackdaw
MrJackdaw / pieChart.js
Created August 26, 2015 18:10
Function for generating a two-color pie chart using D3. Assumes d3 is included and accessible in current scope.
/**
* Params below: use as-is to generate a hollow two-figure pie chart (donut chart)
* @var[width]: pie chart width
* @var[height]: pie chart height
* @var[innerRadius]: inner (hollow) circle radius
* @var[colorRange]: first and second (respective) colors rendered in pie chart
* @var
*/
var width = 90,
height = 90,
@MrJackdaw
MrJackdaw / UIView+Border.swift
Last active January 21, 2019 12:40
Swift 2 Extension for adding a border to one side of a UIView object
extension UIView {
/* Example use: myView.addBorder(
toSide: .Left,
withColor: UIColor.redColor().CGColor,
andThickness: 1.0
)
*/
enum ViewSide {
@MrJackdaw
MrJackdaw / UIView+Border.swift
Last active May 12, 2023 19:02
Swift 3 Extension for adding border to one side of UIView
// This syntax reflects changes made to the Swift language as of Aug. '16
extension UIView {
// Example use: myView.addBorder(toSide: .Left, withColor: UIColor.redColor().CGColor, andThickness: 1.0)
enum ViewSide {
case Left, Right, Top, Bottom
}
@MrJackdaw
MrJackdaw / Inject-Script-Example.js
Last active January 22, 2025 02:08
Reusable class for loading external script files (e.g. from CDN)
// Example usage of Inject-Script.js
// Example 1: Load a script from an external URL. (preferred method)
// You can call this in a React/Vue/whatever component lifecycle, or wherever.
// makes sense. Window globals (e.g. `window.YT`) will be available after calling this.
await injectScriptBySrc("https://www.youtube.com/iframe_api", "yt");
// now you can use `window.YT` methods and properties in your code.
@MrJackdaw
MrJackdaw / animations.css
Last active January 22, 2025 01:33
CSS Quick-Start
/******************************************
* File : Animations.css
*******************************************/
@keyframes fade-in {
from {
opacity: 0;
}
to {
@MrJackdaw
MrJackdaw / AsyncComponentLoader.js
Created April 18, 2019 01:45
React Async Component Loader
import React, { Component } from 'react';
/**
* HOC for asynchronously loading a component dependency.
*
* Use: replace
* import MyComponent from './path/to/my-component';
*
* With:
* const MyComponent = AsyncLoader(() => import('./path/to/my-component'));
@MrJackdaw
MrJackdaw / ImageLoader.css
Last active February 8, 2025 23:52
ReactJS ImageLoader Component (TSX, CSS, and example usage)
/* ImageLoader styles */
.image-loader.image-loader--rounded {
border-radius: 100%;
padding: 0.4rem;
&:hover {
animation: scale-up 250ms linear;
}
}
@MrJackdaw
MrJackdaw / ListView.css
Last active February 10, 2025 22:54
ReactJS ListView Component (TSX, CSS, and example usage)
:root {
--sm: 0.4rem;
--md: 0.6rem;
--lg: 1.2rem;
}
/* */
.list-view {
display: grid;
padding: 0;