Skip to content

Instantly share code, notes, and snippets.

View alexshyba's full-sized avatar
🏀

Alex Shyba alexshyba

🏀
View GitHub Profile
@alexshyba
alexshyba / CustomHead.tsx
Created November 9, 2020 19:32
Disabling Next.js scripts, `NEXT_DATA` and React rehydration
import React from 'react';
import { Head } from 'next/document';
import { cleanAmpPath } from 'next/dist/next-server/server/utils'
function getOptionalModernScriptVariant(path: string) {
if (process.env.__NEXT_MODERN_BUILD) {
return path.replace(/\.js$/, '.module.js')
}
return path
}
@alexshyba
alexshyba / ContextItemChildrenRenderingContentsResolver.cs
Created November 20, 2017 18:20
Sample IRenderingContentsResolver implementations.
using Newtonsoft.Json.Linq;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.LayoutService.Configuration;
using Sitecore.LayoutService.ItemRendering;
using Sitecore.Links;
using Sitecore.Mvc.Presentation;
namespace Nomad.Jss.CodeFirst.ItemRendering
@alexshyba
alexshyba / sym2018-talk-links.md
Last active October 15, 2018 22:06
links from my Sitecore Symposium 2018 talk on Experience the development workflow of your dreams with modern JavaScript and Sitecore JSS
@alexshyba
alexshyba / counter.jsx
Created February 7, 2016 21:39
Counter component
var Counter = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
@alexshyba
alexshyba / GetProps.cs
Created February 7, 2016 20:15
GetProps
private dynamic GetProps()
{
dynamic props = new ExpandoObject();
var dataSourceItem = GetDataSourceItem();
foreach (Field field in dataSourceItem.Fields)
{
if (field.Name.StartsWith("__"))
{
continue;
var config = new JetBrains.dotTrace.Api.SaveSnapshotProfilingConfig(@"C:\perflog\publish_profiling\")
{
ProfilingControlKind = JetBrains.dotTrace.Api.ProfilingControlKind.API,
TempPath = @"C:\perflog\publish_profiling\temp",
//changed this
RedistPath = @"C:\perflog\Redist\",
SavePath = @"C:\perflog\publish_profiling\",
SnapshotFormat = JetBrains.dotTrace.Api.SnapshotFormat.Compressed,
CoreLogMask = 6,
};
@alexshyba
alexshyba / gist:6233235
Created August 14, 2013 17:19
exception
ManagedPoolThread #4 10:17:51 ERROR Cannot start profiler. The directory name is invalid.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.SetCurrentDirectory(String path)
at JetBrains.dotTrace.Api.SelfAttachImpl.StartSelfAttach(BaseProfilingConfig config, String executablePath, String savePath, UInt16 storageFmt)
at JetBrains.dotTrace.Api.SelfAttachImpl.Attach(BaseProfilingConfig config)
@alexshyba
alexshyba / IndexingProvider.cs
Created August 12, 2013 20:47
IndexingProvider.GetHistory
Log.Info("*** IndexingProvider.GetHistory(). Starting processing history collection.", new object());
var result = new HistoryEntryCollection();
foreach (HistoryEntry entry in history)
{
IEnumerable<HistoryEntry> historyEntries = from historyEntry in history
where historyEntry.Action == entry.Action && historyEntry.ItemId == entry.ItemId &&
historyEntry.ItemLanguage == entry.ItemLanguage && historyEntry.ItemVersion == entry.ItemVersion && historyEntry.Created > entry.Created
select historyEntry;
if (historyEntries.Count() > 0)
@alexshyba
alexshyba / gist:6197773
Created August 9, 2013 22:18
Playing with dotTrace SDK
var config = new JetBrains.dotTrace.Api.SaveSnapshotProfilingConfig(@"C:\perflog\publish_profiling\")
{
ProfilingControlKind = JetBrains.dotTrace.Api.ProfilingControlKind.API,
TempPath = @"C:\perflog\publish_profiling\temp",
RedistPath = @"C:\perflog\Redist\JetBrains.dotTrace.ExternalLauncherProcess.exe",
SavePath = @"C:\perflog\publish_profiling\",
SnapshotFormat = JetBrains.dotTrace.Api.SnapshotFormat.Compressed,
CoreLogMask = 6,
};
@alexshyba
alexshyba / gist:6116855
Created July 30, 2013 20:56
Subscribing to item:saved where you can access item changes and do lots of efficient exclusion.
Event.Subscribe("item:saved", this.Item_Saved);
private void Item_Saved([NotNull] object sender, [NotNull] EventArgs e)
{
var changes = Event.ExtractParameter<ItemChanges>(e, 1);
if (!changes.IsFieldModified(FieldIDs.Security) && !changes.IsFieldModified(FieldIDs.Workflow) &&
!changes.IsFieldModified(FieldIDs.WorkflowState))
{
return;