Skip to content

Instantly share code, notes, and snippets.

View drewhamlett's full-sized avatar
Verified

Drew Hamlett drewhamlett

Verified
  • Untappd
  • Wilmington, NC
View GitHub Profile
@Robert-96
Robert-96 / README.md
Last active May 4, 2024 06:05
Ember.Js: Installing Tailwind CSS

Ember.Js: Installing Tailwind CSS

TL;DR

$ ember install ember-cli-postcss                   # Install ember-cli-postcss
$ npm install --save-dev tailwindcss                # Install tailwindcss

$ npx tailwind init app/styles/tailwind.config.js   # Optional: Generate a Tailwind config file for your project  
$ npm install -save-dev postcss-import # Optional: If you want to use the @import statement
@peterc
peterc / embedding_store.rb
Last active December 28, 2023 06:27
Using SQLite to store OpenAI vector embeddings from Ruby
# Example of using SQLite VSS with OpenAI's text embedding API
# from Ruby.
# Note: Install/bundle the sqlite3, sqlite_vss, and ruby-openai gems first
# OPENAI_API_KEY must also be set in the environment
# Other embeddings can be used, but this is the easiest for a quick demo
# More on the topic at
# https://observablehq.com/@asg017/introducing-sqlite-vss
# https://observablehq.com/@asg017/making-sqlite-extension-gem-installable
@robzolkos
robzolkos / stories.rb
Last active September 8, 2023 21:37
story.rb refactor
# Original code https://twitter.com/robinbortlik/status/1699524286568964440?s=20
# app/controllers/stories.rb
class StoriesController < ApplicationController
before_action :check_authorizationa # this should check and return a 401
def create
story = Story.new(story_params)
if story.save
@jnsdbr
jnsdbr / rotate.js
Created August 1, 2014 15:14
Rotating a sprite towards the mouse pointer in phaser.js
window.onload = function()
{
var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '', {
preload: preload,
create: create,
update: update
});
var dragging = false;
@kitze
kitze / store.js
Created January 24, 2018 13:14
simplified redux
import produce from 'immer';
import {createStore} from 'redux';
const handleActions = (actionsMap, defaultState) => (
state = defaultState,
{type, payload}
) =>
produce(state, draft => {
const action = actionsMap[type];
action && action(draft, payload);
@andymatuschak
andymatuschak / gist:c5f2b8b68821a95e5b339bfcd4bfcee1
Last active July 21, 2020 16:59
late-bound React hook callbacks, avoiding subtree re-renders when event callback deps change
function useWeakRef<T>(value: T): React.MutableRefObject<T> {
const ref = useRef(value);
useEffect(() => {
ref.current = value;
}, [value]);
return ref;
}
function useByrefCallback<Args extends unknown[], Result>(
callback: (...args: Args) => Result,
@kitze
kitze / mst-utils.ts
Created March 20, 2020 09:19
mst-utils
import { types, IAnyModelType, Instance, cast } from "mobx-state-tree";
import React, { useMemo } from "react";
export const createModel = <T extends IAnyModelType>(
model: T,
value?: Record<string, any>
) => types.optional(model, () => model.create(value));
export function castSelf<IStoreInstance, IParentModel>(
store: IStoreInstance,
@ianmstew
ianmstew / Avatar.tsx
Last active November 25, 2019 03:44
asyncComputed example
// Parallel implementation to Avatar example from
// https://github.com/conorhastings/use-reducer-with-side-effects/blob/19d097e95302068d8368b0a10b379b0a6bab9f93/README.md
import { useObserver, useLocalStore } from 'mobx-react';
// WIP library inspired by `import { promisedComputed } from 'async-computed-mobx'`
import asyncComputed from 'utils/mobx/asyncComputed';
const DEFAULT_AVATAR = '/assets/img/default-avatar.png';
function Avatar(props: { userName: string }) {
@mundhradevang
mundhradevang / index.html
Created June 5, 2011 04:08 — forked from mbostock/.block
Treemap in D3/SVG with zooming capability
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Treemap</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"></script>
<style type="text/css">
rect {
@javan
javan / bc_require_element.coffee
Created November 28, 2016 20:24
<bc-require>: Basecamp 3's lazy JavaScript loader
BC.registerElement "bc-require",
createdCallback: ->
@setAttribute("pending", "")
attachedCallback: ->
BC.ready =>
if Loader.find(@script)?.loaded
@activate()
else
@deactivate()