Skip to content

Instantly share code, notes, and snippets.

View acflint's full-sized avatar

Alex acflint

  • Grassriots Inc.
  • Vancouver Island, British Columbia
  • 06:02 (UTC -07:00)
View GitHub Profile
@acflint
acflint / nb_signup_tags_bug.rb
Last active February 12, 2024 15:23
Nationbuilder signup_tags bug
# Install HTTParty gem:
# gem install httparty
require "httparty"
@nation_base_url = "https://#######.nationbuilder.com" # update this with your nation.
@api_token = "" # Generate a V2 API token in your nation's control panel and paste it here.
tag_id = "" # Update this with the ID of the tag you want to count. Use a tag that has many records. In my testing I used a tag with 41856 records.
path = "/api/v2/signup_taggings?filter[tag_id]=#{tag_id}&fields[signup_taggings]=signup_id&page[size]=100&page[number]=1"
tagged_record_ids = []
# Install HTTParty gem:
# gem install httparty
require "httparty"
@nation_base_url = "https://#######.nationbuilder.com" # update this with your nation.
@api_token = "" # Generate a V2 API token in your nation's control panel and paste it here.
tag_id = "" # Update this with the ID of the tag you want to count. Use a tag that has many records. In my testing I used a tag with 41856 records.
path = "/api/v2/signups?filter[tag_id]=#{tag_id}&fields[signups]=id&page[size]=100"
tagged_record_ids = []
@acflint
acflint / current_year.js
Last active November 14, 2023 22:23
Current Year in JavaScript
/\d{4}/.exec(Date())[0]
@acflint
acflint / nb_tagged_users.rb
Last active October 19, 2023 14:39
NB Tagged Users API Issue
tagged_record_ids = []
next_path = "/api/v2/signups?filter[tag_id]=#{@tag.nb_id}&fields[signups]=id&page[size]=100"
while next_path
response = @nation.call_api(:get, next_path)
response_body = response.fetch(:body, {})
ids = response_body.fetch("data", []).pluck("id").map(&:to_i)
tagged_record_ids += ids
next_path = response_body.fetch("links", {}).fetch("next", nil)
end
@acflint
acflint / delete_from_paths.js
Last active May 13, 2020 20:10
In NationBuilder you can't delete a Path if there are still people on it, and there is no way to delete people from a Path in batches. So this script is meant to solve that by going through people one by one and deleting them from Paths.
// How to use it:
// 1. Create a filter for the people you want to delete from Paths.
// 2. Paste the below code into your browser's JS console.
// 3. Run removeFromPaths() when you're ready to start.
// A couple of notes:
// 1. This will delete them from all of the paths they're on, not just the specific Path you create a filter for. You could add a filter for a specific path name pretty easily.
// 2. This is hacky and not "proper". Use at your own risk. I'm sorry if this violates any NB terms of use.
function sleep(ms) {
@acflint
acflint / NationBuilder Email Membership Info
Last active December 18, 2018 19:52
Liquid & HTML code to add membership statuses to email blasts
<p style="text-align: center;">{% assign no_membership = true %} {% assign sorted_memberships = recipient.memberships | sort: 'started_at' | reverse %} {% for membership in sorted_memberships | limit: 1 %} {% assign no_membership = false %} {% if membership.status == "active" %} {% capture unixexpires %} {{ membership.expires_on | date: '%s' }} {% endcapture %} {% capture unixnow %} {{ 'now' | date: '%s' }} {% endcapture %} {% assign diff = unixexpires | minus: unixnow %} {% if diff &lt; 5184000 %} {% comment %}THIS IS FOR MEMBERSHIPS EXPIRING SOON{% endcomment %}</p>
<p style="text-align: center;">{{recipient.first_name_or_friend}} -- Your {{ membership.membership_type_name }} membership expires on {{ membership.expires_on | date: '%B %d, %Y' }}. Renew now to continue enjoying your membership benefits.</p>
<div class="nb-tmce-btn" style="width: 200px; display: block; margin-left: auto; margin-right: auto;" contenteditable="false"><!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml"
{% capture social_capital %}
{% case current_signup.capital_amount_in_cents %}
{% when > 10000 %}
100
{% when > 5000 %}
50
{% when > 2000 %}
20
{% else %}
@acflint
acflint / nationbuilder_tickets_memberships.html
Created February 7, 2018 01:02
An example of using membership levels to limit access to ticketed events on NationBuilder.
<!-- Include the membership array partial -->
{% include 'membership_array' %}
<!-- iterate through each ticket level -->
{% for ticket_level in page.event.ticket_levels %}
<!-- this sets the default for membersonly to false -->
{% assign membersonly = false %}
<!-- now we check whether the ticket level name contains "|members:" and if it does we set membersonly to true -->
@acflint
acflint / _membership_array.html
Created February 2, 2018 18:08
Create a comma seperated array of a person's active memberships in Nationbuilder
{% assign memberships = '' %}
{% for membership in current_signup.memberships %}
{% assign memberships = memberships | concat: membership.membership_type_name | concat: ", " %}
{% endfor %}
{% assign memberships = memberships | downcase %}
@acflint
acflint / pages_show_event_wide.html
Last active February 2, 2018 18:19
Limiting Nationbuilder event tickets by membership level.
<!-- Include the membership array partial -->
{% include 'membership_array' %}
<!-- iterate through each ticket level -->
{% for ticket_level in page.event.ticket_levels %}
<!-- this sets the default for membersonly to false -->
{% assign membersonly = false %}