Skip to content

Instantly share code, notes, and snippets.

@dperetti
dperetti / xed.sh
Created March 9, 2021 23:39
xed alternative for CodeStory
#!/bin/bash
# xed alternative
# xed currently has a tendency to crash or make XCode stall
# for several seconds when it is used to open a file at
# a specific line.
if [ "$1" = "-l" ] || [ "$1" = "--line" ] ; then
line=$2
file=$3
else
line=1
@dperetti
dperetti / ContextMenuArea.tsx
Created February 24, 2020 23:55
Improved react-electron-contextmenu
import * as React from 'react'
import { remote } from 'electron'
const { Menu } = remote
export interface Props<T> {
menuItemsFactory: (data: T) => Electron.MenuItemConstructorOptions[];
data: T;
style?: any;
}
@dperetti
dperetti / machine.js
Last active August 7, 2019 08:23
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@dperetti
dperetti / pouchdb.js
Created September 22, 2018 15:51
PouchDB Flowtype definitions (WIP)
// @flow
export type PouchDBPostResponse = { ok: true, id: string, rev: string }
export type PouchDBUpsertResponse = { updated: true, id: string, rev: string } | { updated: false }
export type PouchDBRemoveResponse = { ok: true, id: string, rev: string, } | { ok: false }
export type PouchDBFindResponse<T> = { docs: Array<T>, warning?: string }
export type PouchDBAllDocsResponse<T> = { rows: Array<{ doc: T, id: string, key: string, value: { rev: string } }>, total_rows: number }
export type PouchError = { // empirically found
docId: string,
@dperetti
dperetti / odiff.js
Created September 22, 2018 15:33
odiff Flowtype definition
// @flow
declare module 'odiff' {
declare export default function odiff(A: any, B: any): Array<{|
type: 'set',
path: Array<string | number>,
val: any,
|} | {|
type: 'unset',
path: Array<string | number>,
@dperetti
dperetti / codemirror.js
Last active August 10, 2017 21:31
CodeMirror Flow libdef (Partial)
declare module 'codemirror' {
declare export default typeof CodeMirror
declare type Position = { line: number, ch: number }
declare class TextMarker {
changed(): void;
clear(): void;
find(): { from: Position, to: Position };
}
@dperetti
dperetti / call_modal_client.js
Last active February 27, 2020 05:54
Meteor Handlebars modal pattern
Session.set('modalData', {template: "modal-backups", title: "Backup", files: [{name: "blah", date: new Date()}]});
$('#myModal').modal();
@dperetti
dperetti / IAPViewController.m
Created January 13, 2013 11:00
Trigger the update of a single item in a tableView
- (void)tableViewUpdatePerformance:(Performance *)performance {
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:[self.performances indexOfObject:performance] inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}