Skip to content

Instantly share code, notes, and snippets.

@jhorsman
jhorsman / main.cpp
Created January 26, 2018 18:09
Blink for Node MCU; Blinking the builtin led on GPIO pin 2.
/**
* Blink for Node MCU
* also see https://arduino.stackexchange.com/questions/38477/does-the-node-mcu-v3-lolin-not-have-a-builtin-led
*
* Turns on an LED on for one second,
* then off for one second, repeatedly.
*/
#include "Arduino.h"
// On a NodeMCU board the built-in led is on GPIO pin 2
@jhorsman
jhorsman / runOnce.java
Last active January 16, 2018 07:48
Run once on application startup with a scheduler (JAVA). See https://stackoverflow.com/a/31304767/1678525. If you truely need to run something only once, this is a better way: https://stackoverflow.com/a/17037758/1678525
@EnableScheduling
@Component
public class ScheduledTasks {
private static final Logger LOGGER = LoggerFactory.getLogger(ScheduledTasks.class);
private static boolean needToRunStartupMethod = true;
@Scheduled(fixedRate = 3600000)
public void keepAlive() {
@jhorsman
jhorsman / WebRequestExperiment.java
Last active January 15, 2018 08:49
Use the DXA 1.7 ContentProvider and Localization without a web request.
package org.example;
import com.sdl.webapp.common.api.WebRequestContext;
import com.sdl.webapp.common.api.content.ContentProvider;
import com.sdl.webapp.common.api.content.ContentProviderException;
import com.sdl.webapp.common.api.localization.Localization;
import com.sdl.webapp.common.api.localization.LocalizationResolver;
import com.sdl.webapp.common.api.model.PageModel;
import lombok.extern.slf4j.Slf4j;
import org.example.controller.SwitchController;
@jhorsman
jhorsman / cm-binary-queries.sql
Last active January 11, 2018 09:09
A set of handy queries to inspect how much space item binaries (i.e. multimedia components, template building block assemblies) are using in the Tridion Content Manager database.
/* The queries below use data in a temp table, so at a minimum execute the queries for the temp table, and then use one or more of the queries on the BINARY table */
/*** CREATE THE TEMP TABLE ***/
/* Clear the temp table to be sure */
If(OBJECT_ID('tempdb..#CURRENT_ITEM_BINARIES') Is Not Null)
Begin
Drop Table #CURRENT_ITEM_BINARIES
End
/* figure out which binaries are used by current (not old) versions of items */
@jhorsman
jhorsman / database-size.sql
Last active January 11, 2018 10:01
Run an SQL query on MS SQL to figure out the database of a database.
/* Select database size */
SELECT DB_NAME(db.database_id) DatabaseName,
(CAST(mfrows.RowSize AS FLOAT)*8)/1024 RowSizeMB,
(CAST(mflog.LogSize AS FLOAT)*8)/1024 LogSizeMB,
(CAST(mfstream.StreamSize AS FLOAT)*8)/1024 StreamSizeMB,
(CAST(mftext.TextIndexSize AS FLOAT)*8)/1024 TextIndexSizeMB
FROM sys.databases db
LEFT JOIN (SELECT database_id, SUM(size) RowSize FROM sys.master_files WHERE type = 0 GROUP BY database_id, type) mfrows ON mfrows.database_id = db.database_id
LEFT JOIN (SELECT database_id, SUM(size) LogSize FROM sys.master_files WHERE type = 1 GROUP BY database_id, type) mflog ON mflog.database_id = db.database_id
LEFT JOIN (SELECT database_id, SUM(size) StreamSize FROM sys.master_files WHERE type = 2 GROUP BY database_id, type) mfstream ON mfstream.database_id = db.database_id
@jhorsman
jhorsman / MyPageController.class
Last active January 9, 2018 13:21
Custom page controller for DXA JAVA. Also see https://tridion.stackexchange.com/a/18256/88
@Controller
public class MyPageController {
// Inject the PageController, because we cannot override and change the RequestMapping
@Autowired
private PageController pageController;
// This mapping is more specific than the DXA PageController mapping
@RequestMapping(
value = {"/**"},
@jhorsman
jhorsman / move-old-outlook-mail.ps1
Last active January 9, 2018 13:21
Start the year with a fresh, empty mailbox. This scripts moves emails from the Inbox (default folder) in a date range to another folder.
<#
Start the year with a fresh, empty mailbox.
This scripts moves emails from the Inbox (default folder) in a date range to another folder.
Set $filterFromDate and $filterToDate to select the date range of mails to move.
Set $tagetFolderName to the folder to move the mails to.
Inspired by https://social.technet.microsoft.com/Forums/scriptcenter/en-US/5dc36dec-f88f-4e2d-8cba-385b6204ef6c/powershell-and-outlook-moving-messages?forum=ITCG
and https://msdn.microsoft.com/en-us/magazine/dn189202.aspx
#>
@jhorsman
jhorsman / web.config
Last active January 9, 2018 13:22
Disable browserlink in a ASP.NET webapp
<appSettings>
<!-- Disable browserlink, it causes unnecessary calls to the content service -->
<add key="vs:EnableBrowserLink" value="false" />
</appSettings>
@jhorsman
jhorsman / enable-iis.ps1
Last active January 9, 2018 13:22
Install / enable IIS on Windows 10; With the default IIS options
# based on the script in this post
# https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installation-with-Powershell#AdditionalIISFeatures
#
# and the list of default IIS options from
# https://www.howtogeek.com/112455/how-to-install-iis-8-on-windows-8/
# and http://nl.tinypic.com/r/29z6kvs/9
#
# and a hint from https://gist.github.com/yetanotherchris/c51757d221eecb150867b7b113d227e8