Skip to content

Instantly share code, notes, and snippets.

@hijonathan
hijonathan / example.html
Last active February 12, 2024 01:30
Generate a unique id in a Jinja template.
<!-- Jinja Unique ID Generator -->
{% macro random_int(len) -%}
{% for n in range(len) %}
{{ [0,1,2,3,4,5,6,7,8,9]|random }}
{% endfor %}
{%- endmacro %}
{% macro unique_id(count_groups=5, group_len=6, separator='-') -%}
{% set parts %}
@hijonathan
hijonathan / form.html
Last active August 1, 2023 19:14
Submit a HubSpot form with AJAX without redirecting the user.
<form class='form-inline' id='my-custom-form'>
<div class="form-group">
<input type='email' class='form-control' placeholder='Your email address' required>
</div>
<button class="btn btn-primary" type='submit'>Sign up</button>
</form>
<!-- Actual form that gets submitted to HubSpot -->
<div class="hidden" id='hubspot-form'>
<script charset="utf-8" src="//js.hsforms.net/forms/current.js"></script>
@hijonathan
hijonathan / example.coffee
Last active February 14, 2023 15:14
Javascript implementation of the largest remainder method http://en.wikipedia.org/wiki/Largest_remainder_method
values = [
13.626332
47.989636
9.596008
28.788024
]
# Round these percentage values into integers, ensuring that they equal 100% at the end.
roundedValues = getLargestRemainder values, 100
# [14, 48, 9, 29]
@hijonathan
hijonathan / instructions.markdown
Created October 4, 2012 19:58
Steps to transfer Chrome Custom Search Engines to Alfred

Step 0: Quit Chrome

Step 1: Get a dump of your search engines

> pwd
/Users/jonathankim/Desktop

> sqlite3 ~/Library/Application\ Support/Google/Chrome/Default/Web\ Data
sqlite3> .output chrome_export.sql

sqlite3> .dump keywords

@hijonathan
hijonathan / inline.html
Created August 2, 2021 00:59
Implementing next/previous post functionality in Webflow with js. See https://www.mokupet.com/resources for a live example.
<script type="text/javascript">
/*
* Heavily based on https://discourse.webflow.com/t/native-linking-to-previous-and-next-post-or-page-using-cms/19525/19
* This one uses regular ol' javascript instead of jQuery.
*
* # How this script works:
*
* 1. It looks for a hidden collection on the page and gets all the items in it.
* 2. Using the current item, it identifies the items before and after it.
* 3. It then looks for the prev and next buttons on the page and updates those with the correct links.
/**
* Passphrase.
* Simple passphrase entry
*/
const accessMap = {
"tennessee": ['Caroline', 'Clay'],
"leia": ['Dog Walkers'],
"coffee": ['Jonathan', 'Connie']
};
(function(w, doc) {
const cookieKey = 'your_cookie';
let hasCookie = doc.cookie.split(';').filter((c) => {
let [k, _v] = c.split('=');
return k == cookieKey;
}).length > 0;
if (!hasCookie) {
@hijonathan
hijonathan / readme.md
Last active September 16, 2019 11:43
Fun in-browser web scraper.

What is this?

This little script lets you easily define a few things you want from a web page (using CSS selectors), the crawl the site until you get them all.

It's based on the way Kimono works, but it's much simpler and has no limit to the number of results you can get. It also uses your auth tokens from the browser, so it's just as secure as your browser (which you should still be suspect of).

How do I use it?

Put that script into your browser terminal and run it. If you use Chrome, I highly recommend saving it as a snippet for easy reuse. To start scraping a site, create a Scraper instance with your desired options:

@hijonathan
hijonathan / notifications.md
Created December 7, 2012 19:12
Mark a notification as read

In your email:

<img src="https://path/to/mark-as-read?notificationId=1234&source=email" width="1" height="1" />

Bonus server-side:

When that endpoint is hit from an email, delay the response for 5-10s and listen for the connection being terminated early from the client. If they make it past 5-10s, then mark the notification as read. If not, then either they skimmed it or it was a fluke request.

@hijonathan
hijonathan / index.html
Created May 28, 2016 01:05
Appcues + Intercom
<!-- ... Appcues scripts installed higher up ... -->
<!-- Intercom Installation -->
<script>
window.intercomSettings = {
// TODO: The current logged in user's full name
name: 'Jonathan Kim',
user_id: '123456',
first_name: 'Jonathan',
email: 'get@me.bro.com',