Bart's Snippets

Test Importing 20 Bills

test_20_bill_imports.go
package main

import (
        "fmt"
        "os/exec"
)

func main() {
        urls := make([]string, 20)
        urls[0] = "hb17-1001"
        urls[1] = "hb17-1002"
        urls[2] = "hb17-1003"
        urls[3] = "hb17-1004"
        urls[4] = "hb17-1005"
        urls[5] = "hb17-1006"
        urls[6] = "hb17-1007"
        urls[7] = "hb17-1008"
        urls[8] = "hb17-1009"
        urls[9] = "hb17-1010"
        urls[10] = "hb17-1011"
        urls[11] = "hb17-1012"
        urls[12] = "hb17-1013"
        urls[13] = "hb17-1014"
        urls[14] = "hb17-1015"
        urls[15] = "hb17-1016"
        urls[16] = "hb17-1017"
        urls[17] = "hb17-1018"
        urls[18] = "hb17-1019"
        urls[19] = "hb17-1020"

        for _, url := range urls {
                fmt.Printf("importing %s\n", url)
                cmd := exec.Command("drush", "coga_import_bill", url)
                err := cmd.Run()
                if err != nil {
                        fmt.Printf("Command finished with error: %v", err)
                }

        }
}

Break Up String and Grab first 3 lines

archiver.ex
defmodule Archiver do                                                                                                                             
  def archive(url, user_id, bookmark_id) do                                                                                                       
    summary = Readability.summarize(url)                                                                                                          
    page = summary.article_html                                                                                                                   
    path = "priv/static/archive/#{user_id}"                                                                                                       
    unless File.exists?(path) do                                                                                                                  
      File.mkdir(path)                                                                                                                            
    end                                                                                                                                           
    File.write("#{path}/#{bookmark_id}.html", page)                                                                                               
  end                                                                                                                                             
end   

Break Up String and Grab first 3 lines

test.ex
%{body: body} = BigSnips.Repo.get(BigSnips.Snippet, 2)
String.split(body, "\n")  |> 
Enum.take(3) |> 
Enum.join("\n")

Add paragraph to a node programmatically

add_paragraph_drupal.php
$node = node_load(...);
$entity = entity_create('paragraphs_item', array('field_name' => 'name_of_field_in_node', 'bundle' => 'name_of_paragraph_bundle'));
$entity->setHostEntity('node', $node);
$entity->save();

Loop 10 times in bash

for i in `seq 1 10`; do drush @cga.prod sapi-i 1 100 10; done

bill search view

$view = new view();
$view->name = 'bill_search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'search_api_index_cga_main_index';
$view->human_name = 'Bill Search';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Bill Search';
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['search_api_bypass_access'] = 0;
$handler->display->display_options['query']['options']['entity_access'] = 0;
$handler->display->display_options['query']['options']['parse_mode'] = 'direct';
$handler->display->display_options['exposed_form']['type'] = 'better_exposed_filters';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '25';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '7';
$handler->display->display_options['pager']['options']['tags']['first'] = '';
$handler->display->display_options['pager']['options']['tags']['previous'] = 'Prev';
$handler->display->display_options['pager']['options']['tags']['next'] = 'Next';
$handler->display->display_options['pager']['options']['tags']['last'] = '';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'entity';
$handler->display->display_options['row_options']['view_mode'] = 'search';
/* Header: Global: Result summary */
$handler->display->display_options['header']['result']['id'] = 'result';
$handler->display->display_options['header']['result']['table'] = 'views';
$handler->display->display_options['header']['result']['field'] = 'result';
$handler->display->display_options['header']['result']['content'] = 'Displaying @start - @end of @total results';
/* Field: Indexed Content: Node ID */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'bill' => 'bill',
);
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Search Bill Name, Bill #, or Keyword';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['search_api_views_fulltext']['mode'] = 'filter';
/* Filter criterion: Indexed Content: Bill Type */
$handler->display->display_options['filters']['field_bill_type']['id'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_bill_type']['field'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_bill_type']['expose']['operator_id'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['label'] = 'Bill Type';
$handler->display->display_options['filters']['field_bill_type']['expose']['operator'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['identifier'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['type'] = 'select';
/* Filter criterion: Indexed Content: Chamber of Origination */
$handler->display->display_options['filters']['field_chamber']['id'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_chamber']['field'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_chamber']['expose']['operator_id'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['label'] = 'Chamber of Origination';
$handler->display->display_options['filters']['field_chamber']['expose']['operator'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['identifier'] = 'field_chamber';
/* Filter criterion: Indexed Content: Sessions */
$handler->display->display_options['filters']['field_sessions']['id'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_sessions']['field'] = 'field_sessions';
/* Filter criterion: Indexed Content: Subjects */
$handler->display->display_options['filters']['field_subjects']['id'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_subjects']['field'] = 'field_subjects';

/* Display: Full */
$handler = $view->new_display('page', 'Full', 'full');
$handler->display->display_options['defaults']['exposed_form'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'better_exposed_filters';
$handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Ascending';
$handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Descending';
$handler->display->display_options['exposed_form']['options']['bef'] = array(
  'general' => array(
    'input_required' => 0,
    'text_input_required' => array(
      'text_input_required' => array(
        'value' => 'Select any filter and click on Apply to see results',
        'format' => 'full_html',
      ),
    ),
    'allow_secondary' => 0,
    'secondary_label' => 'Advanced options',
    'secondary_collapse_override' => '0',
  ),
  'sort' => array(
    'bef_format' => 'default',
    'advanced' => array(
      'collapsible' => 0,
      'collapsible_label' => 'Sort options',
      'combine' => 1,
      'combine_param' => 'sort_bef_combine',
      'combine_rewrite' => '',
      'reset' => 0,
      'reset_label' => '',
      'is_secondary' => 0,
    ),
  ),
  'search_api_views_fulltext' => array(
    'bef_format' => 'default',
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_chamber' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_bill_type' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_sessions' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
  'field_subjects' => array(
    'bef_format' => 'default',
    'slider_options' => array(
      'bef_slider_min' => '0',
      'bef_slider_max' => '99999',
      'bef_slider_step' => '1',
      'bef_slider_animate' => '',
      'bef_slider_orientation' => 'horizontal',
    ),
    'more_options' => array(
      'is_secondary' => 0,
      'any_label' => '- All -',
      'bef_filter_description' => '',
      'tokens' => array(
        'available' => array(
          0 => 'global_types',
        ),
      ),
      'rewrite' => array(
        'filter_rewrite_values' => '',
      ),
    ),
  ),
);
$handler->display->display_options['exposed_block'] = TRUE;
$handler->display->display_options['defaults']['sorts'] = FALSE;
/* Sort criterion: Search: Relevance */
$handler->display->display_options['sorts']['search_api_relevance']['id'] = 'search_api_relevance';
$handler->display->display_options['sorts']['search_api_relevance']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['search_api_relevance']['field'] = 'search_api_relevance';
$handler->display->display_options['sorts']['search_api_relevance']['order'] = 'DESC';
$handler->display->display_options['sorts']['search_api_relevance']['exposed'] = TRUE;
$handler->display->display_options['sorts']['search_api_relevance']['expose']['label'] = 'Most Relevant';
/* Sort criterion: Indexed Content: Bill Number */
$handler->display->display_options['sorts']['field_bill_number']['id'] = 'field_bill_number';
$handler->display->display_options['sorts']['field_bill_number']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['field_bill_number']['field'] = 'field_bill_number';
$handler->display->display_options['sorts']['field_bill_number']['exposed'] = TRUE;
$handler->display->display_options['sorts']['field_bill_number']['expose']['label'] = 'Bill #';
/* Sort criterion: Indexed Content: Last Action Date */
$handler->display->display_options['sorts']['field_date']['id'] = 'field_date';
$handler->display->display_options['sorts']['field_date']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['field_date']['field'] = 'field_date';
$handler->display->display_options['sorts']['field_date']['exposed'] = TRUE;
$handler->display->display_options['sorts']['field_date']['expose']['label'] = 'Last Action';
/* Sort criterion: Indexed Content: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['expose']['label'] = 'Bill Topic';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'bill' => 'bill',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['group'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Bill #, Sponsor, or Keyword';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
  11 => 0,
  16 => 0,
  21 => 0,
  26 => 0,
  31 => 0,
  36 => 0,
);
/* Filter criterion: Indexed Content: Chamber of Origination */
$handler->display->display_options['filters']['field_chamber']['id'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_chamber']['field'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['value'] = array(
  2 => '2',
  1 => '1',
);
$handler->display->display_options['filters']['field_chamber']['group'] = 1;
$handler->display->display_options['filters']['field_chamber']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_chamber']['expose']['operator_id'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['label'] = 'House of Origin';
$handler->display->display_options['filters']['field_chamber']['expose']['operator'] = 'field_chamber_op';
$handler->display->display_options['filters']['field_chamber']['expose']['identifier'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
  11 => 0,
  16 => 0,
  21 => 0,
  26 => 0,
  31 => 0,
);
$handler->display->display_options['filters']['field_chamber']['is_grouped'] = TRUE;
$handler->display->display_options['filters']['field_chamber']['group_info']['label'] = 'House of Origin';
$handler->display->display_options['filters']['field_chamber']['group_info']['identifier'] = 'field_chamber';
$handler->display->display_options['filters']['field_chamber']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'House',
    'operator' => '=',
    'value' => array(
      1 => '1',
    ),
  ),
  2 => array(
    'title' => 'Senate',
    'operator' => '=',
    'value' => array(
      2 => '2',
    ),
  ),
);
$handler->display->display_options['filters']['field_chamber']['type'] = 'select';
/* Filter criterion: Indexed Content: Bill Type */
$handler->display->display_options['filters']['field_bill_type']['id'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_bill_type']['field'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['value'] = array();
$handler->display->display_options['filters']['field_bill_type']['group'] = 1;
$handler->display->display_options['filters']['field_bill_type']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_bill_type']['expose']['operator_id'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['label'] = 'Type';
$handler->display->display_options['filters']['field_bill_type']['expose']['operator'] = 'field_bill_type_op';
$handler->display->display_options['filters']['field_bill_type']['expose']['identifier'] = 'field_bill_type';
$handler->display->display_options['filters']['field_bill_type']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['field_bill_type']['type'] = 'select';
/* Filter criterion: Indexed Content: Sessions */
$handler->display->display_options['filters']['field_sessions']['id'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_sessions']['field'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['group'] = 1;
$handler->display->display_options['filters']['field_sessions']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_sessions']['expose']['operator_id'] = 'field_sessions_op';
$handler->display->display_options['filters']['field_sessions']['expose']['label'] = 'Session';
$handler->display->display_options['filters']['field_sessions']['expose']['operator'] = 'field_sessions_op';
$handler->display->display_options['filters']['field_sessions']['expose']['identifier'] = 'field_sessions';
$handler->display->display_options['filters']['field_sessions']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['field_sessions']['type'] = 'select';
/* Filter criterion: Indexed Content: Subjects */
$handler->display->display_options['filters']['field_subjects']['id'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['field_subjects']['field'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['value'] = array();
$handler->display->display_options['filters']['field_subjects']['group'] = 1;
$handler->display->display_options['filters']['field_subjects']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_subjects']['expose']['operator_id'] = 'field_subjects_op';
$handler->display->display_options['filters']['field_subjects']['expose']['label'] = 'Subject';
$handler->display->display_options['filters']['field_subjects']['expose']['operator'] = 'field_subjects_op';
$handler->display->display_options['filters']['field_subjects']['expose']['identifier'] = 'field_subjects';
$handler->display->display_options['filters']['field_subjects']['expose']['multiple'] = TRUE;
$handler->display->display_options['filters']['field_subjects']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
);
$handler->display->display_options['filters']['field_subjects']['type'] = 'select';
$handler->display->display_options['path'] = 'bill-search';

/* Display: Simple */
$handler = $view->new_display('page', 'Simple', 'simple');
$handler->display->display_options['exposed_block'] = TRUE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Indexed Content: Content type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'bill' => 'bill',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Search: Fulltext search */
$handler->display->display_options['filters']['search_api_views_fulltext']['id'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['table'] = 'search_api_index_cga_main_index';
$handler->display->display_options['filters']['search_api_views_fulltext']['field'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['group'] = 1;
$handler->display->display_options['filters']['search_api_views_fulltext']['exposed'] = TRUE;
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator_id'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['label'] = 'Search by Bill # (ex. HB17-1001), Sponsor, or Keyword';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['operator'] = 'search_api_views_fulltext_op';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['identifier'] = 'search_api_views_fulltext';
$handler->display->display_options['filters']['search_api_views_fulltext']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
  5 => 0,
  6 => 0,
  11 => 0,
  16 => 0,
  21 => 0,
  26 => 0,
  31 => 0,
  36 => 0,
  41 => 0,
);
$handler->display->display_options['filters']['search_api_views_fulltext']['mode'] = 'filter';
$handler->display->display_options['path'] = 'bill-search';