Skip to content

Instantly share code, notes, and snippets.

View aaronshaf's full-sized avatar

Aaron Shafovaloff aaronshaf

View GitHub Profile
#!/bin/bash
# Check if an argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <number_of_branches>"
exit 1
fi
# Number of branches to create
NUM_BRANCHES=$1
@aaronshaf
aaronshaf / fn.sh
Created November 30, 2023 02:42
shell utils for listing and deleting git branches
function b() {
local branches branch
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format="%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:blue)%(contents:subject)%(color:reset) %(color:green)(%(committerdate:relative))%(color:reset) [%(color:red)%(authorname)%(color:reset)]") \
&& branch=$(echo "$branches" | fzf --ansi --no-sort) \
&& branch=$(echo "$branch" | awk '{print $1}' | sed 's/\* //') \
&& git checkout "$branch"
}
function db() {
local branches branch
@aaronshaf
aaronshaf / sift-documents.sh
Created June 2, 2023 17:37
sift files into folders by year (or year and month)
#!/bin/bash
## this script moves all files (not folders) in ~/Documents into folder called ~/Documents/[year]
## where [year] is the year the file was created
# Find files with extensions and move them into appropriate year folders
find ~/Documents -maxdepth 1 ! -name ".*" -name "*.*" | while IFS= read -r file; do
# Extract the year from the file's creation timestamp
year=$(stat -f "%Sm" -t "%Y" "$file")
@aaronshaf
aaronshaf / generate-css-stylesheet.js
Last active January 11, 2019 22:35
Generate CSS variables from instructure-ui theme
const sort = (a, b) => (a < b ? -1 : 1);
function generateVars(theme) {
let cssParts = [];
for (const [key, val] of Object.entries(theme.variables)) {
if (typeof val === "string") {
cssParts.push(`--${key}: ${val};`);
} else if (typeof val === "object") {
for (const [key2, val2] of Object.entries(val)) {
cssParts.push(`--${key}-${key2}: ${val2};`);
@aaronshaf
aaronshaf / is-reason-ready-yet.md
Last active February 20, 2020 14:45
Is ReasonML ready yet?

No.

Very important

  • Remove postinstall requirement on bs-platform for deploy (see 2127, 2772, 3164)

Nice to have

  • BuckleScript support for sourcemaps (1699)
  • async syntax (1321)
@aaronshaf
aaronshaf / App.jsx
Last active March 3, 2018 20:02
Experiment with managing state with callbags / pipelines
const initialState = { count: 0 };
const pipeline = map(([state, data]) => ({ count: state.count + data }));
class App extends Component {
render() {
return (
<CallbagState initialState={initialState} pipeline={pipeline}>
{(state, send) => (
<div>
<button onClick={send(1)}>Add 1</button>
let getIt = () =>
Js.Promise.(
Fetch.fetch(url)
|> then_(Fetch.Response.json)
|> then_((json) => Js.Json.decodeObject(json) |> resolve)
|> then_((obj) => Js.log(obj /* how can I get obj.message? */) |> resolve)
);
[%bs.raw {|require('./app.css')|}];
[@bs.module] external logo : string = "./logo.svg";
let component = ReasonReact.statelessComponent("App");
let make = (~message, _children) => {
...component,
render: (_self) =>
<div className="App">
class ThingsFetcher extends React.Component {
constructor (props) {
super(props)
this.state = {
data: null,
isLoading: false,
wasLoadedSuccessfully: false,
error: null
}
}
shouldComponentUpdate (nextProps, nextState) {
const changedProps = {}
for (const prop in this.props) {
if (this.props[prop] !== nextProps[prop]) {
changedProps[prop] = true
}
}
if (Object.keys(changedProps).length) {
console.debug(changedProps)