Skip to content

Instantly share code, notes, and snippets.

View cwilper's full-sized avatar

Chris Wilper cwilper

View GitHub Profile
@cwilper
cwilper / javascript-nerd-test.js
Created September 26, 2016 01:17
Javascript Nerd Test
#!/usr/bin/env node
"use strict";
// what does this function return?
function a()
{
return
{
i: 1

Manual Solr Dump and Load via CSV

Solr has built-in CSV export and import facilities, which can be used to copy data from one core to another.

You can use the following process to select documents from one core and move them to another, using only the Solr Admin UI, Chrome, and curl.

Dump CSV from source core

  1. Use the Solr Admin UI's Query screen to formulate a query for the subset of documents you want to dump.
  2. Run the query and click on the link that gives you the raw query results.
@cwilper
cwilper / BAx.md
Last active March 17, 2017 19:22
@cwilper
cwilper / TimesheetSnippet.vba
Created April 15, 2017 02:30
Excel VBA code snippets
'If G and H are defined for the given row, add the difference to K and clear them
Private Sub Update_Total(ByVal Row As Integer)
Dim punchStart, punchEnd, timeWorked As Integer
punchStart = Range("G" & Row).Value
punchEnd = Range("H" & Row).Value
timeWorked = punchEnd - punchStart
If (punchStart > 0 And punchEnd > 0 And timeWorked > 0) Then
Range("K" & Row).Value = Range("K" & Row) + timeWorked
Range("G" & Row).Value = ""
Range("H" & Row).Value = ""
@cwilper
cwilper / ImDim.java
Last active April 20, 2017 19:01
Get image size from file
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
/**
@cwilper
cwilper / checkok.sh
Created July 10, 2017 15:02
Checks if a given url returns 200 ok and returns 0 if so, returns 1 (error) otherwise
#!/bin/sh
curl -Ssf "$1" > /dev/null
if [[ $? -ne 0 ]]; then
echo "Error: Non-200 returned for url $1"
exit 1
fi
#!/bin/bash
#
# Repeatedly performs rsyncs with the given arguments until
# the output seems to indicate there are no more changes, or
# a maximum number of iterations is reached, whichever comes first.
#
# Invoke the same way you would rsync. Verbose output is forced, since
# that's how it detects if any changes were transferred..so specifying
# -v is redundant.
#
@cwilper
cwilper / Person.ts
Last active March 7, 2018 19:04
Typescript example: Constructor with optional args via interface.
// 1. Define an interface for the optional args to your constructor.
interface PersonArgs {
nickname?: string;
age?: number;
}
class Person {
// 2. Add the args as the last parameter of the constructor, with a default value of {}.
@cwilper
cwilper / nginx.conf
Created March 15, 2018 19:28
Nginx Permanent Redirect for Handle Prefix Change
server {
# Permanently redirect default DSpace handle prefix URLs to new, registered handle prefix
rewrite ^/handle/123456789/(.*)$ /handle/PUT-REGISTERED-PREFIX-HERE/$1 permanent;
}
@cwilper
cwilper / CommandRunner.java
Last active January 30, 2019 14:19
Java example of using ProcessBuilder synchronously and reading stdout/err from temporary files. See main method.
package com.atmire.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;