Skip to content

Instantly share code, notes, and snippets.

View MrLeebo's full-sized avatar
🤪

Jeremy Liberman MrLeebo

🤪
View GitHub Profile
@MrLeebo
MrLeebo / Layout_CaseIndentation.rb
Last active April 19, 2022 14:19
rubocop formatting styles
# In all examples, the rubocop default is listed first
# IndentOneStep: false
case owner
when 'I'
attrs[:user] = @current_user
when 'they'
attrs[:user] = @it
end

ruby from a js dev perspective

This isn't an exhaustive introduction to the ruby language. Instead I wanted to talk about what makes ruby different from JavaScript and other languages that you may have experience with

destructing arrays and objects

in JS, we can deconstruct both arrays and objects into variables

// array destructuring
@MrLeebo
MrLeebo / Feedback.tsx
Created March 29, 2021 03:13
Minimal sample of a blitzjs/nextjs server rendered form submission
import { urlencoded } from "body-parser"
import * as z from "zod"
const feedbackForm = z.object({
email: z.string().email(),
message: z.string(),
})
interface Props {
flash?: string
import { prefetchQuery } from "react-query";
describe('MyComponent', () => {
beforeEach(() => {
// using react-query for data fetching makes it easy to mock out your API calls
return prefetchQuery(["myQuery"], () => [{ name: 'Steve', role: 'Developer' }])
})
it('should open a dialog', async () => {
// visit the page
<App>
<ErrorBoundary>
<Routes />
</ErrorBoundary>
</App>
/// action creators ////////////////////////////////////////////////////////////
// exposing action creators as functions so the caller doesn't have to worry
// about typos when dispatching actions; e.g. dispatch(clear())
// mark in state that the refetch is being performed
export const beginFetch = payload => ({ type: 'beginFetch', payload })
// request a new refetch
export const refetch = () => ({ type: 'refetch' })
const initialValues = {
username: "",
email: "",
password: "",
passwordConfirmation: "",
}
// always give your component a name, even if it is the default export,
// because it will appear in the Component Trace when there is a React error
export default function SignupForm() {
@MrLeebo
MrLeebo / dist-index.html
Created December 14, 2018 22:43
Demonstration of webpack w/ xml-loader (filenames containing "-" represent folders) https://dist-qwxwourdxw.now.sh/
<!DOCTYPE html>
<html>
<body>
<script src="main.js"></script>
</body>
</html>
@MrLeebo
MrLeebo / example21-grouping.js
Created May 4, 2018 21:02
Modified grouping example to show grouping and column reordering
const faker = require('faker');
const ReactDataGrid = require('react-data-grid');
const exampleWrapper = require('../components/exampleWrapper');
const React = require('react');
const {
ToolsPanel: { AdvancedToolbar: Toolbar, GroupedColumnsPanel },
Data: { Selectors },
DraggableHeader: { DraggableContainer },
Formatters: { ImageFormatter }
} = require('react-data-grid-addons');
@MrLeebo
MrLeebo / index.js
Last active April 9, 2018 20:22
Learning neural networks
const brain = require('brain.js')
const mimir = require('mimir')
const net = new brain.NeuralNetwork
// The specific structure here isn't important, this exists
// simply to teach the NN these words.
const voc = mimir.dict([
"a conflict of programmers",
"a murder of crows",
"a flock of geese",