Skip to content

Instantly share code, notes, and snippets.

View cwilper's full-sized avatar

Chris Wilper cwilper

View GitHub Profile
@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 {}.
#!/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 / 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
@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 / 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 / BAx.md
Last active March 17, 2017 19:22

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 / 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
#!/bin/bash
#
# Dumps a subset of one Solr core and loads it into another one.
#
# WARNING: THIS DUMP AND LOAD IS LOSSY -- DO NOT USE IT FOR BACKUPS!
# In particular, multi-valued fields won't import in the target exactly as they were in the source.
#
# Before running, change the variables below as needed for your task.
#

Keybase proof

I hereby claim:

  • I am cwilper on github.
  • I am cwilper (https://keybase.io/cwilper) on keybase.
  • I have a public key whose fingerprint is 9316 C0C1 B5A6 2552 5568 335D 1173 084A BA6C 1222

To claim this, I am signing this object: