Skip to content

Instantly share code, notes, and snippets.

@SergeyAxenov
SergeyAxenov / trim.sh
Created December 14, 2017 03:52
Trims leading and trailing slash
#!/usr/bin/env bash
string='/this is my string'
[[ $string =~ ^/(.*) ]] && string=${BASH_REMATCH[1]}
[[ $string =~ (.*)/$ ]] && string=${BASH_REMATCH[1]}
echo $string
@SergeyAxenov
SergeyAxenov / zeppelin-web|WEB-INF|web.xml
Created March 31, 2017 00:22
Configures additional virtual folder in Zeppelin web server to keep web assets for Zeppelin angular apps outside of Zeppelin installation folder (i.e. when it is in a container). The main purpose is to take client side angular UI code out of zeppelin notebook and store it in normal html, js, css files
<!--
~ Configures additional virtual folder in Zeppelin web server
~ to keep web assets for Zeppelin angular apps outside of
~ Zeppelin installation folder (i.e. when it is in a container)
~ The main purpose is to take client side angular UI code out of
~ zeppelin notebook and store it in normal html, js, css files
-->
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--

Zeppelin 0.6.2. On angular watch initialization steps in client-first scenarious.

Zeppelin angular client-first

Zeppelin angular client-first is defined as an %angular paragraph with generated HTML output which is activated by an auto-run script:

<script>
changeValue($scope, value) {
	$scope.myValue=value
}
(function() {
	... 
@SergeyAxenov
SergeyAxenov / ZeppelinAngularBindWatchChange.scala
Created March 17, 2017 01:10
Zeppelin 0.6.2 Angular. Trying to watch a variable before binding first is not going to work
// Demonstrates usual z Angular bind/watch/change scenario (watch is working)
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
val logger: Logger = LoggerFactory.getLogger("MyZeppelinLogger");
logger.debug("START");
z.angularUnwatch("ax4_var")
z.angularUnbind("ax4_var")
logger.debug("Setting ax4_var=Init before watch");
@SergeyAxenov
SergeyAxenov / ZeppelinPersistParagraphData.scala
Created March 16, 2017 01:35
Zeppelin 0.6.2 Use GUI params to save arbitrary paragraph data between the interpreter restarts
// Shows how to persist paragraph data between spark interpreter restarts using Zeppelin GUI params storage
// Run it once, then restart interpreter and run again. Parameter "ax4_gui_param" shuld be restored
val ctx = z.getInterpreterContext
val param = ctx.getGui.getParams().get("ax4_gui_param")
if (param == null) {
s"Parameter is not persisted. Setting initial value"
ctx.getGui.getParams().put("ax4_gui_param","hello_gui_param")
} else {
s"Parameter is restored from Zeppelin GUI params collection: $param"
}
@SergeyAxenov
SergeyAxenov / ZeppelinGetAllAngularObjects.scala
Last active March 15, 2017 05:15
Zeppelin 0.6.2 - How to get all registered angular objects
// 1. Zeppelin InterpreterContext
// 2. How to get all angular objects registered in the note
z.angularBind("ax4_var","value")
val ctx = z.getInterpreterContext
ctx.getAngularObjectRegistry().getAllWithGlobal(ctx.getNoteId())
z.angularUnbind("ax4_var")
ctx.getAngularObjectRegistry().getAllWithGlobal(ctx.getNoteId())
// OUTPUT:
@SergeyAxenov
SergeyAxenov / ZeppelinAngularWatch.scala
Last active March 15, 2017 05:16
Zeppelin 0.6.2 angular watch
// 1. Sequence of binding events on angular watch
// 2. nulls are accepted as both initial and new value
// 3. using the same value (even null) twice triggers the watch
// 4. Multiple watchers on the same variable
// 5. Bug in watch (before, after)
// 6. Use watch (before, after, context) - it is working as expected
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
val logger: Logger = LoggerFactory.getLogger("MyZeppelinLogger");
@SergeyAxenov
SergeyAxenov / ZeppelinLogger.scala
Last active October 21, 2021 14:51
Logging from an Apache Zeppelin spark paragraph into a separate log file
// ================================================================
// Gist
// Zeppelin Version 0.6.2
// Logging from zeppelin into a separate log file
// ================================================================
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
val logger: Logger = LoggerFactory.getLogger("MyZeppelinLogger");
@SergeyAxenov
SergeyAxenov / smo-IsServerOnline.ps1
Last active August 29, 2015 14:20
PowerShell check whether SQL server is online using SMO
# #powershell #ps #sql #smo #status #isOnline
Import-Module “sqlps” -DisableNameChecking
function SMO-IsServerOnline {
[CmdletBinding()]
[OutputType([boolean])]
Param(
[string]$serverName
)
$srv = new-object Microsoft.SqlServer.Management.Smo.Server($serverName)
@SergeyAxenov
SergeyAxenov / msdeploy_runcommand.ps1
Last active August 29, 2015 14:20
MSDeploy RunCommand in PowerShell
# #powershell #ps #msdeploy #runCommand
function MsDeploy-RunCmd(
[string]$msdeployExe,
[string]$svr,
[string]$site,
[string]$command) {
$source="runcommand='$command'"
$dest="auto,computername=`"https://$($svr):8172/msdeploy.axd?site=$site`",authtype=`"NTLM`""
$cmd = $(" `"$msdeployExe`" -verb=sync -source={0} -dest={1} -allowuntrusted" -f $source, $dest)