Skip to content

Instantly share code, notes, and snippets.

View acorcutt's full-sized avatar
Making Stuff

Anthony Corcutt acorcutt

Making Stuff
View GitHub Profile
@acorcutt
acorcutt / sharp-image-merge-test.js
Created February 27, 2022 21:47
Testing sharp image merge
import sharp from 'sharp';
export default async function handler(req, res) {
const { url, logo } = req.query || [];
const imgRes = await fetch(url);
const logoRes = await fetch(logo);
//return res.status(200).json({ url, status: imgRes.status });
const imgBuffer = Buffer.from(await imgRes.arrayBuffer());
const logoBuffer = Buffer.from(await logoRes.arrayBuffer());
@acorcutt
acorcutt / _app.js
Last active June 23, 2021 12:04
Next.js Page Transition
// Tailwinds Styles
import '../styles/globals.css';
import { useRouter } from 'next/router';
import { useState, useEffect } from 'react';
import classNames from 'classnames';
function MyApp({ Component, pageProps }) {
const [transition, setTransition] = useState('opacity-100');
@acorcutt
acorcutt / transform.js
Created September 25, 2017 21:41
Nested transform with ramda
let data = {
title: "Hello ",
address: {
house: "123",
street: "ok"
},
list: [{a:1,b:2}]
}
let transformations = {
@acorcutt
acorcutt / gist:432b0f80ccf7c4298bdc165e4770c715
Last active September 25, 2017 21:40
Transform props with Ramda & recompose
// Transform props { listingEditQuery: { Listing: { title: 'Title' }} => { listing: { title: 'Title' }}
withProps(R.compose(R.objOf('listing'), R.path(['listingEditQuery', 'Listing'])))
inputChange = (e) => {
console.log('inputChange', e.currentTarget.name, e.currentTarget.value );
this.props.apolloClient.writeFragment({
id: 'new', //this.props.profileQuery.Profile.id,
fragment: gql`
fragment Profile on Profile {
__typename
${e.currentTarget.name}
}
@acorcutt
acorcutt / Cloud9GithubOrg
Created April 13, 2017 20:52
Allow Cloud9 to push to org repo
To allow c9 workspace to push to github org repository you must allow it in 3rd party access setup https://github.com/organizations/<org>/settings/oauth_application_policy
Either remove restrictions or allow it from your https://github.com/settings/applications
@acorcutt
acorcutt / SVG
Created May 29, 2013 19:53
SVG with fallbacks
/* browsers that support svg support multiple bg those that dont browsers will fallback to image */
.css{
background: url('image.png');
background: none, url('vector.svg');
}
Most modernd browsers support svg in images, just use conditional comments to serve images instead for old IE
<!--[if lte IE 8]><img src="logo.png" /><![endif]-->
<!--[if gt IE 8]><img src="logo.svg" /><![endif]-->
@acorcutt
acorcutt / import.js.erb
Created May 8, 2012 14:11
Import URL into assets pipeline
// Instead of copying js plugins to assets/ import them from a url.
// Obviously works best with pre-compiled assets
<%=open('https://raw.github.com/documentcloud/backbone/master/backbone.js
').read%>
@acorcutt
acorcutt / Indexer.rb
Created November 26, 2011 19:49
Indextank Indexer
module Indexer
# Add indexed fields to model
# TODO - make this work in embedded e.g. self.index_embedded(*names)
module Indexes
extend ActiveSupport::Concern
included do
class_attribute :_index_fields
class_attribute :_index_texts
@acorcutt
acorcutt / gist:1099813
Created July 22, 2011 16:41
Post array of text_field's in rails as array
<%-# items is an array on object e.g. object.items = [1,2,3], we want to display as list of fields, and post back as an array - note the backwards ][ which makes is do this! -%>
<% @object.items.each do |i| %>
<%=f.text_field "items][",:value=>i,:id=>"item-#{SecureRandom.uuid}" %>
<% end %>