Skip to content

Instantly share code, notes, and snippets.

View nikitaeverywhere's full-sized avatar
🇺🇦
Just build it!

Nikita Savchenko nikitaeverywhere

🇺🇦
Just build it!
View GitHub Profile
@nikitaeverywhere
nikitaeverywhere / formatDate.js
Last active August 29, 2015 14:14
NodeJS date formatting function (appeared because NodeJS is not using the system locale and Date.toLocaleString gives unexpected result)
/**
* Converts any date to "DD.MM.YYYY, hh:mm:ss" string.
* Workaround for NodeJS Date.toLocaleString implementation.
*
* @param {Date} date - Date to format.
* @returns {string} - Formatted date string.
*/
var formatDate = function (date) {
return date.toISOString().replace(/(\d+)\-(\d+)\-(\d+)T\s?([^\.]*)\..*/, "$3.$2.$1, $4");
};
@nikitaeverywhere
nikitaeverywhere / central.css
Last active August 29, 2015 14:20
Pure CSS solution for centering content always on middle center of parent relative block.
/*
Pure CSS solution for centering content always on middle center of parent relative block.
*/
.central {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
/*
* This CSS describes the basics of trick to make CSS-only navigation.
* This type of navigation uses #anchors to switch pages.
* In this CSS anchor #page-main as well as empty anchor (#) describes the main page.
* Valid markup for this example:
* <div class="pages">
* <div class="page"> Page content 1 </div>
* <div class="page"> Page content 2 </div>
* </div>
*/
/**
* Code snippet for students ^^
* Tarnavsky used this function to find t^-1 from prime number t and m.
* Usage: var tMinusOne = getRevT(m, t);
* Test case 1: getRevT(121, 5) === 97
* Test case 2: getRevT(9, 7) === 13
*/
function getRevT (m, t) {
function stage (a, b) {
var r = a % b, q = Math.floor(a/b);
@nikitaeverywhere
nikitaeverywhere / gist:6310513
Last active December 21, 2015 13:09
SuperRegular expression for breaking Caché code to lexical parts. It can be improved! Supports ##class, $Method/$Var, $$MyMethod, $$$Macro, ^Global, ..ClassMethod, %SystemClass, "strings", 016175, {[()]}.
/**
* Function breaks code for parts with span tags and according styles, but skips &*; html-symbol combinations and tag <br>
*
* @param string
* String to parse.
* @returns {string}
* Parsed string.
*/
this.highlightHTML = function(string) {
return string.replace(/(\/\*.*?(?=\*\/)\*\/)|([0-9]+\.?[0-9]+?)|(((<|&|&#)|(\^%?)|\/|\${0,3}|#{0,2}|%|\.|(\.\.))?[A-Za-z0-9]+[;>]?)|[{}\]\[\(\)!_'\\#\?\+\-\*\/=<>,]|("[^"]*")/g,
@nikitaeverywhere
nikitaeverywhere / XData-UrlMap.xml
Last active January 9, 2016 15:46
Implementation-very-basic-draft
<Routes>
<!-- Self-documenting links variant: allow <Route> tag to nest additional info -->
<Route Url="/posts" Method="GET" Call="ShowPosts">
<!-- One of many variants, most applicable for Caché XData scheme on my opinion -->
<!-- Nested <Link>s tell what we can do with the current element -->
<Link rel="add" method="POST" href="/posts"/>
<Link rel="next" method="POST" href="/posts/:page"/>
<!-- Nested <LinkGroup>s tell what we can do with the content on the page -->
<LinkGroup name="post">
@nikitaeverywhere
nikitaeverywhere / MyPackage.xml
Last active March 14, 2016 22:51
Перед вами - пример веб-приложения Caché, которое устанавливает себя самостоятельно после импорта XML-файла. Сохраните архив, нажав вверху на "Download ZIP", разархивируйте и импортируйте его в Caché. Затем, откройте http://localhost:[port]/myWebApp/ (не забудьте добавить косую черту в конце!) и убедитесь, что приложение работает.
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2016.2 (Build 590U)" ts="2016-03-15 00:40:16">
<Class name="MyPackage.Installer">
<CompileAfter>MyPackage.REST</CompileAfter>
<Super>%Projection.AbstractProjection</Super>
<TimeChanged>63992,1953.207424</TimeChanged>
<TimeCreated>63992,1916.587195</TimeCreated>
<Parameter name="WebAppName">
<Type>%String</Type>
@nikitaeverywhere
nikitaeverywhere / semCompare.js
Created June 28, 2016 11:08
JavaScript: compare semantic versions
/**
* Semantic versioning versions compare.
* @param {string} high
* @param {string} low
* @returns {boolean}
* @author ZitRo (zitros.lab@gmail.com)
* @license MIT http://www.opensource.org/licenses/mit-license.php
*/
function versionGT (high, low) {
let v1 = high.split(/[\-\.]/g),
/// Original: https://github.com/eduard93/Utils/blob/master/Utils/REST.cls.xml
Class Utils.REST Extends %CSP.REST
{
XData UrlMap
{
<Routes>
<Route Url="/file" Method="GET" Call="GET"/>
</Routes>
}
/**
* Just a piece of code to start.
*/
const host = "127.0.0.1:57772";
let ws = new WebSocket(`ws://${ host }/csp/user/WebCourse.ChatWebSocket.cls`);
ws.addEventListener(`open`, () => {
console.log(`We are connected to the chat!`);
});