Skip to content

Instantly share code, notes, and snippets.

View JofArnold's full-sized avatar

Jof JofArnold

View GitHub Profile
@JofArnold
JofArnold / grunt-contrib-concat-json
Created July 26, 2013 17:13
Snippet of Gruntfile.coffee code to wrap a number of json files and attach them to the namespace. Requires grunt-contrib-concat. More flexible than using some of the grunt json packages
concat:
json:
src: ['source/files/here.json']
dest: 'output/files/here.js'
options:
banner: "(function(namespace){\n'use strict'\nnamespace.json={};\n"
footer: "\n})(YOURNAMESPACEHERE)"
process: (src,filepath) ->
arr = filepath.split '/'
filename = arr[arr.length-1]
@JofArnold
JofArnold / bem-v-css-modules.scss
Last active December 31, 2016 11:05
How BEM encourages inflation of code whereas CSS modules compares reduction of code
/*
You have a component called MyComponent.jsx and a decidated "locally scoped"
scss file called MyComponent.scss.
For one of the HTML nodes you wish to add a clearfix using something like:
*/
...:after {
clear: both;
content: ".";

The problem with SASS mixins*

  1. mixins with SASS can balloon your css files quickly.
  2. mixins stop it being clear where stuff came from (can't search for class names for instance).

WARNING: The below is pseudo-code as I'm too lazy to double-check the APIs, output etc:

@mixin flexThing {
  color: red;
@JofArnold
JofArnold / donut.js
Created September 29, 2017 09:49
Donut Chart using Styled Components
import React, { Component } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
const dimsFromProps = ({ size, strokeWidth, value }) => {
const halfsize = size * 0.5;
const radius = halfsize - strokeWidth * 0.5;
const circumference = 2 * Math.PI * radius;
const strokeVal = value * circumference / 100;
const dashVal = strokeVal + " " + circumference;
@JofArnold
JofArnold / downshift-example.js
Last active October 9, 2023 04:43
Example of how to use Downshift as a controlled component with arbitrary items
// Untested code, but hopefully it gives you an idea.
// Ping me @jofarnold on Twitter if you get stuck
import React, { Component } from "react";
import Downshift from "downshift";
import PropTypes from "prop-types";
function nodeFromItem(id, items) {
return items.find(({ uuid }) => uuid === id);
}
@JofArnold
JofArnold / NavLink.js
Created February 1, 2018 18:58
React Router NavLink with inactiveClassName and isActive child function enhancements
@JofArnold
JofArnold / Login.m
Last active October 26, 2022 13:31
Using promises in React Native modules with Swift
// Created by react-native-create-bridge
// import RCTBridgeModule
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include(“RCTBridgeModule.h”)
#import “RCTBridgeModule.h”
#else
#import “React/RCTBridgeModule.h” // Required when used as a Pod in a Swift project
#endif
@JofArnold
JofArnold / Fastfile
Last active July 5, 2021 09:21
Fastfile for creating apps on App Store Connect as well as certs, building and uploading to Testflight
# --------------------------------------------------------------------------------
#
# About
#
# Here is a useful Fastfile for delivering a multiple varients (targets) of an app
# to, ultimately, Testflight.
# The project is called "cione" and has two schemes and two targets called
# "cione" and "citwo".
@JofArnold
JofArnold / BoredApeYachtClub.sol
Last active April 9, 2023 12:44
The Bored Ape Yacht Club (BAYC) Solidity Smart Contract GitHub
/**
*Submitted for verification at Etherscan.io on 2021-04-22
*/
// File: @openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
@JofArnold
JofArnold / Loot.sol
Created September 19, 2021 08:51
@dhof's original Loot smart contract
/**
*Submitted for verification at Etherscan.io on 2021-08-27
*/
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the