Skip to content

Instantly share code, notes, and snippets.

View zachelrath's full-sized avatar

Zach McElrath zachelrath

View GitHub Profile
@zachelrath
zachelrath / SimplePulsarMessageListener.java
Created May 19, 2022 13:54
Simple pulsar message listener
@Service
@Slf4j
@ConditionalOnProperty(name = "consumer.enabled", havingValue = "true")
public class SimpleMessageListener implements MessageListener<byte[]> {
private final int maxConsumeDelaySeconds;
private static final String CONSUMER_PREFIX = "(CONSUMER) [{}]: ";
public SimpleMessageListener(
@zachelrath
zachelrath / SimplePulsarQueueConsumer.java
Created May 19, 2022 13:52
Simple Pulsar queue consumer
@Configuration
@ConditionalOnProperty(name = "consumer.enabled", havingValue = "true")
@Slf4j
public class PulsarConsumerConfiguration {
private final PulsarClient client;
private final List<Consumer> consumers;
private final SimpleMessageListener msgListener;
public PulsarConsumerConfiguration(
@zachelrath
zachelrath / StructuredLoggingWithMap.java
Created February 15, 2022 15:36
Log4j structured logging with a Map
logger.info(new ObjectMessage(Map.of(
"totalItems", orderItems.size(),
"items", orderItems
)));
@zachelrath
zachelrath / StructuredLoggingWithObjectMessage.java
Last active February 15, 2022 15:20
Structured data logging with Log4j ObjectMessage
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ItemLog {
private Integer totalItems;
private List<OrderItem> items;
public ItemLog(List<OrderItem> items) {
this.items = items;
this.totalItems = items.size();
}
@zachelrath
zachelrath / DynamicModelsAndComponents.xml
Last active January 7, 2021 21:06
A Skuid Page with JavaScript code for creating Models and Components dynamically from JavaScript
<skuidpage showsidebar="true" showheader="true">
<models>
<model id="DummyUserModel" datasource="salesforce" sobject="User" limit="1" query="false"/>
</models>
<components>
<custom name="DynamicTableAndModel"/>
</components>
<resources>
<labels/>
<javascript>
@zachelrath
zachelrath / jQuery vs. DOM Native Methods: Check all checkboxes in a page
Last active February 7, 2020 16:50
Comparison of the complexity between jQuery and DOM Native syntax required to find all checkboxes in a given page and automatically check them.
// jQuery
$('input[type="checkbox"]').prop('checked',true);
// DOM
Array.prototype.slice.call(document.querySelectorAll('input[type="checkbox"]')).forEach(function(e){e.setAttribute("checked","checked");});
id first_name last_name email gender username birthdate
1 Freda Scotland fscotland0@purevolume.com Female fscotland0 6/20/85
2 Martainn Manners mmanners1@cpanel.net Male mmanners1 8/18/94
3 Benjy Biers bbiers2@multiply.com Male bbiers2 5/1/62
4 Jean Ickovits jickovits3@boston.com Male jickovits3 9/26/55
5 Cyrus Hamlett chamlett4@forbes.com Male chamlett4 9/7/53
6 Shayne Estabrook sestabrook5@cam.ac.uk Male sestabrook5 1/17/75
7 Nolie Szymonwicz nszymonwicz6@chicagotribune.com Female nszymonwicz6 9/4/95
8 Janette Ratchford jratchford7@deliciousdays.com Female jratchford7 2/17/93
9 Alissa Oloshkin aoloshkin8@about.com Female aoloshkin8 8/16/92
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true">
<models>
<model id="Input" limit="20" query="true" createrowifnonefound="true" datasource="Ui-Only" processonclient="true">
<fields>
<field id="Data" displaytype="TEXT" label="Data"/>
<field id="ImportStatus" displaytype="PICKLIST" label="Import Status" ogdisplaytype="TEXT" picklistsource="manual" returntype="TEXT" defaultvaluetype="fieldvalue" defaultValue="ready" enclosevalueinquotes="true">
<picklistentries>
<entry value="inprogress" label="In Progress"/>
<entry value="ready" label="Ready"/>
</picklistentries>
<skuidpage showsidebar="false" showheader="true" tabtooverride="Contact">
<models>
<model id="Contact" limit="100" query="true" createrowifnonefound="false" sobject="Contact">
<fields>
<field id="CreatedDate"/>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="Birthdate"/>
<field id="Name"/>
</fields>
@zachelrath
zachelrath / Sync PermissionSetAssignments with Custom Setting field
Created October 1, 2013 18:54
Skuid Snippets for adding/removing PermissionSetAssignments based on the value of a field in Custom Setting record(s)
// Row Action snippet
skuid.snippet.registerSnippet('SyncPermSets_RowAction',function(){
skuid.snippet.getSnippet('UpdatePermissionSetAssignmentsForUsers')({
rows:[arguments[0].item.row]
});
});
// Mass Action snippet
skuid.snippet.registerSnippet('SyncPermSets_MassAction',function(){
var rows = [];