Skip to content

Instantly share code, notes, and snippets.

@przmv
przmv / string-replace-all.xsl
Created September 16, 2010 13:51
String replace all with XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
@przmv
przmv / addcolumn.sql
Created October 10, 2010 07:13
Add column to MySQL table if it's not exists
DROP PROCEDURE IF EXISTS AddColumn;
DELIMITER '//'
CREATE PROCEDURE AddColumn(
IN dbName TINYTEXT,
IN tableName TINYTEXT,
IN fieldName TINYTEXT,
IN fieldDef TEXT)
BEGIN
IF NOT EXISTS (
@przmv
przmv / array.rc
Last active December 11, 2015 05:39
Associative arrays implementation in rc shell script. Thanks to bnwr on #suckless for the idea ...and implementations
#!/usr/local/plan9/bin/rc
path=$PLAN9/bin
# List with odd items as keys and even items as values
data=('foo' 'bar' \
'bar' 'baz' \
'test' 'passed' \
'foo' 'one more bar' \
'dummy' 'qwerty' \
@przmv
przmv / penultimate-fork.rc
Created March 8, 2013 05:21
Return penultimate (i.e. last but one) item from the list (rc)
#!/usr/bin/env rc
# Return penultimate (i.e. last but one) item from the list
fn penultimate {
lbo=`{echo $#* -1|bc}
echo -n $*($lbo)
}
data=(item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item item it
@przmv
przmv / data-uri.rc
Last active January 3, 2016 01:59
data-uri generator in rc
#!/usr/bin/env rc
path=($PLAN9/bin)
fn datauri {
echo data:`{/usr/bin/file -bi $1 | sed 's/ //'}^';'base64,`{/usr/bin/base64 $1 | tr -d '\x0A'}
}
if(~ $#* 0)
echo usage: `{basename $0} file... >[1=2]
@przmv
przmv / jsonval.sh
Created January 30, 2014 09:46 — forked from cjus/jsonval.sh
#!/bin/bash
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
echo ${temp##*|}
}
json=`curl -s -X GET http://twitter.com/users/show/$1.json`
prop='profile_image_url'
picurl=`jsonval`
@przmv
przmv / interval.go
Created May 25, 2015 09:14
gonx interval reducer
package elblog
import (
"time"
"github.com/pshevtsov/gonx"
)
const (
IntervalHourly = -1 * time.Hour
@przmv
przmv / glow_bench.go
Created April 6, 2016 19:31
gonx vs glow
package main
import (
"crypto/md5"
"flag"
"fmt"
"strings"
"github.com/chrislusf/glow/flow"
)
@przmv
przmv / rebuild.R
Created February 26, 2018 11:21
Rebuild Dygraphs for R project and docs
#!/usr/bin/env Rscript
library(roxygen2)
library(rmarkdown)
pkg <- "dygraphs"
roxygen2::roxygenize(pkg)
install.packages(pkg, repos = NULL, type = "source")
rmarkdown::render_site(paste(pkg, "docs", sep = "/"))

Keybase proof

I hereby claim:

  • I am pshevtsov on github.
  • I am pshevtsov (https://keybase.io/pshevtsov) on keybase.
  • I have a public key ASDPcdbEgEoNZXQVYAnwyHpD2_Tf6zQuslEFJXw83_u4hgo

To claim this, I am signing this object: