Skip to content

Instantly share code, notes, and snippets.

@edmangimelli
edmangimelli / offline_hn.rb
Created August 28, 2022 22:32
super simple grab offline copy of hacker news
# offline_hn.rb
# super-simple-grab-offline-copy-of-hacker-news
# description:
# - grabs the links on the front page of hacker news
# - grabs each linked page, and each page of comments
# - combines it all into one offline-able html
# usage:

When giving a block to a method, I think of it as sending a special proc argument.

You can send regular positional arguments, or kwargs, and you can also send 1 special proc argument.

When you use the literal syntax:

some_method { |x| x.to_s }

it's called a block, though it's really just a special syntax for a proc (special syntax in that it ends up having an elevated status in the method body (see yield)).

# ls aliases
#
# in the context of the current directory
#
# l list everything
# ld list just the directories
# lf list just the files
#
# ^^^ these can be coupled with some modifiers.
# modifier examples:

can't stand typing target.value; love type ellipses?

const Input = props => {
  const onChange = props.onChange && (({target}) => props.onChange(target.value));
  return <input {...{...props, ...onChange && {onChange}}} />;
}

:troll_face:

I've recently started wrapping the inside of my recursive functions to protect them against renaming/passing:

For instance, say you have:

let factorial = n => {
  if (n == 1) return 1;
  return n * factorial(n-1);
}
20190402
:shipit: using computers to answer deep questions
e='ve';r='y'; r=a=>c=>e<=c<=a<=r; i='s'; r`aviol`(i) ? true : false
????????
🐙 ☕☕☕☕☕☕
++[------>+<]>.++[->++<]>+.-[-->+<]>.........---[-->+++<]>-.+[--->++<]>+.+[----->+<]>.++[-->+++<]>.[--->++<]>.+[--->++<]>+..+++.---.........+++.

A Small Example of the Convenience of Currying

A while back I made a helper function:

export const accessor = (obj, defaultValue = null) => x => _.get(obj, x, defaultValue);

Pretty straightforward. It's just a function which creates a custom version of lodash's get for a specific object. Great for react.

@edmangimelli
edmangimelli / backup_db_to_s3.rake
Last active January 12, 2019 02:41
rails rake task for backing up heroku database to s3 bucket
# this gist was inspired by hopsoft's
# https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# and a snippet given to me by mckbeardy on Midwest Dev Chat (Zach Mckenzie)
# put this file in lib/tasks
# your_rails_project/lib/tasks/backup_db_to_s3.rake (or whatever you want to name it)
#
# usage:
#
# rails db:backup_to_s3