Skip to content

Instantly share code, notes, and snippets.

View simple17's full-sized avatar

Alexander Khripko simple17

  • FirstLine software
  • Montenegro
View GitHub Profile
@simple17
simple17 / console.js
Last active December 13, 2023 10:40
[console methods] #js
// count time
console.time("Loop timer")
for(i = 0; i < 10000; i++){
// Some code here
}
console.timeEnd("Loop timer")
//group
console.group("My message group");
@simple17
simple17 / chords.js
Created July 21, 2021 12:26
[Generate chords] #js
const notes = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'Ab', 'Bb', 'Cb', 'Db', 'Eb', 'Fb', 'Gb'];
const chords = ['', '7', 'm', 'm7', 'maj7', 'dim', 'm7-5'];
chords.map(ch => notes.map(n => n+ch)).flat().sort(() => Math.random() - 0.5).join(' ')
@simple17
simple17 / datetime.ts
Created February 3, 2021 08:15
[DateTime to Date]
export const dateTimeToDate = (dotNetDate: string): Date => {
var re = /(\/Date\()(\d*)(\)\/)/;
var millisecondsString = dotNetDate?.replace(re, "$2") ?? '';
return millisecondsString ? new Date(parseInt(millisecondsString)) : new Date();
}
@simple17
simple17 / check.jsx
Created July 29, 2020 11:22
[check why it was rendered] #react
// if (process.env.NODE_ENV === 'development') {
// const whyDidYouRender = require('@welldone-software/why-did-you-render');
// whyDidYouRender(React, {
// trackAllPureComponents: true,
// });
// }
@simple17
simple17 / ConvertHelper.cs
Created July 11, 2020 09:11
[Render Block into string] #episerver
using System.IO;
using System.Web.Mvc;
namespace Foundation.Helpers
{
public static class ConvertHelper
{
public static string RenderViewToString(ControllerContext context, string viewName, object model)
{
if (string.IsNullOrEmpty(viewName))
@simple17
simple17 / fillTemplate.js
Last active May 29, 2020 11:44
[fillTemplate]
export const fillTemplate = (templateString, templateVars) => {
return templateString ? templateString.replace(/{([^{}]*)}/g,
function(a, b) {
var r = templateVars[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
) : '';
};
////
@simple17
simple17 / el.jsx
Created May 14, 2020 12:54
[expand element] #react
(props) => {
const [elHeight, setElHeight] = useState(0);
const elRef = useRef(null);
const onButtonClick = (e) => {
elHeight ? setElHeight(0) : setElHeight(elRef.current.scrollHeight);
};
const elStyle = {
maxHeight: elHeight,
};
@simple17
simple17 / scroll.scss
Created May 13, 2020 09:33
[Hide scrollbar]
overflow-y: scroll;
-ms-overflow-style: none;
&::-webkit-scrollbar {
display: none;
}
@simple17
simple17 / controller.cs
Created April 22, 2020 12:48
[Get StartPage] #episerver
using System.Web.Mvc;
using EPiServer;
using EPiServer.Core;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Web.Mvc;
using EPiServer.Web.Mvc.Html;
namespace Foundation.Features.Blocks
{
[TemplateDescriptor(Default = true)]
@simple17
simple17 / vp.js
Created April 15, 2020 11:14
[Detect Viewport]
const vw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
const vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);