Skip to content

Instantly share code, notes, and snippets.

@elifarley
elifarley / dt2asbigint.sql
Created January 8, 2016 17:36
DateTime2 to BigInt - MS SQL
-- Monotonic function that returns a bigint representing a given datetime2.
CREATE FUNCTION dt2asbigint(@dt datetime2) RETURNS BIGINT WITH SCHEMABINDING AS
BEGIN
declare @twoAsBigInt bigint = 2
declare @bytesInDate int = 3
declare @bitsInTime int = 8 * (8 - @bytesInDate)
declare @bigdatetime binary(9) = cast(@dt as binary(9))
declare @bigdate bigint = cast(reverse(substring(@bigdatetime, 7, @bytesInDate)) as binary(3))

Keybase proof

I hereby claim:

  • I am elifarley on github.
  • I am elifarley (https://keybase.io/elifarley) on keybase.
  • I have a public key whose fingerprint is BC7E 5B5D 4A0F A9EF ACB2 BC4F CE2A D059 C465 A677

To claim this, I am signing this object:

package java.net;
public class GetLocalHostInfo {
public static InetAddressImpl impl;
public static void main( final String[] args ) {
try {
InetAddress.getLoopbackAddress();
<settingsSecurity>
<relocation>/Volumes/usb-key/settings-security.xml</relocation>
</settingsSecurity>
package org.ecc.numericnotation;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
/**
*
@elifarley
elifarley / jstatd.sh
Created April 20, 2015 20:05
JVM monitoring
# On remote server:
echo 'grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission; };' > /tmp/tools.policy
sudo -u jboss $JDK_HOME/bin/jstatd -J-Djava.rmi.server.hostname=$(hostname -i) -J-Djava.security.policy=/tmp/tools.policy
@elifarley
elifarley / mercurial.ini
Last active August 29, 2015 14:18
Some useful aliases for Mercurial DVCS
# Save this file as %USERPROFILE%\mercurial.ini or ~/.hgrc
[alias]
nudge = push --rev .
clean = clean --abort-on-err
cleana = clean --all
qic = !%HG% qimport -r .:: && %HG% qpop -a $@
qfa = !%HG% qpush -a $@ && %HG% qfinish -a
metaimport = !%HG% export $@ | %HG% import --user "%HGUSER%" --bypass -
metaimportnc = !%HG% export $@ | %HG% import --user "%HGUSER%" --no-commit --similarity 50 -
@elifarley
elifarley / 0_reuse_code.js
Last active August 29, 2015 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@elifarley
elifarley / reql.py
Last active August 29, 2015 14:16 — forked from RedBeard0531/functions.js
Compute sample standard deviation, coefficient of variation and other stats over large datasets in RethinkDB using Map-Reduce in ReQL. See https://github.com/rethinkdb/rethinkdb/issues/3769#issuecomment-77229538
> load('functions.js')
> db.stuff.drop()
false
> db.stuff.insert({value:1})
> db.stuff.insert({value:2})
> db.stuff.insert({value:2})
> db.stuff.insert({value:2})
> db.stuff.insert({value:3})
> db.stuff.mapReduce(map, reduce, {finalize:finalize, out:{inline:1}}).results[0]
{