Skip to content

Instantly share code, notes, and snippets.

View SQiShER's full-sized avatar
👨‍👩‍👧
Work, Family, Sleep, Repeat

Daniel Bechler SQiShER

👨‍👩‍👧
Work, Family, Sleep, Repeat
View GitHub Profile
@SQiShER
SQiShER / build.gradle
Last active August 29, 2015 13:57
Gradle Cargo Plugin configuration example for isolated containers
def availablePortFinder = AvailablePortFinder.createPrivate()
def tomcatDownloadUrl = 'http://.../apache-tomcat-7.0.50.zip'
def cargoHome = "$buildDir/cargo"
// ...
buildscript {
repositories {
jcenter()
}
@SQiShER
SQiShER / ByteArrayDiffer.java
Last active September 14, 2015 10:51
Custom Differ for java-object-diff to add "equals-only" byte array support
import de.danielbechler.diff.NodeQueryService;
import de.danielbechler.diff.access.Instances;
import de.danielbechler.diff.differ.Differ;
import de.danielbechler.diff.differ.DifferDispatcher;
import de.danielbechler.diff.differ.DifferFactory;
import de.danielbechler.diff.node.DiffNode;
import java.util.Arrays;
public class ByteArrayDiffer implements Differ
@SQiShER
SQiShER / gist:1111424
Created July 28, 2011 11:41
This is the reason why Lucene scoring was a little bit off for searches with very short terms (if I recall correctly)
private final Similarity similarity = new DefaultSimilarity()
{
private static final long serialVersionUID = 1L;
@Override
public byte encodeNormValue(final float f)
{
return SmallFloat.floatToByte52(f);
}
@SQiShER
SQiShER / IsTheAppleStoreOnline.sh
Created May 17, 2012 14:14
Script for OS X that checks every 2 minutes whether the Apple Store is online and notifies you as soon as it's back online. Great if you want to buy a new product before its sold out!
#!/bin/sh
while [ true ]
do
if [ $(curl -XGET "http://store.apple.com/de" | grep "We'll be back soon" | wc -l) -eq 0 ]
then
say -v Alex 'The Apple Store is back online!'
growlnotify -m 'The Apple Store is back online!' -t 'Apple Store'
fi
sleep 120
@SQiShER
SQiShER / example.json
Last active November 5, 2015 15:42
GraphQL question: how to query for all items of a map without knowing the field names?
{
"id-123": {
"name": "foo"
},
"id-456": {
"name": "bar"
}
}
@SQiShER
SQiShER / ios-command-line-tests.md
Last active December 13, 2015 23:19
The bumpy road to iOS Command-Line builds. A step-by-step guide. (Work in progress)
  • Configure a new (shared) Scheme to run tests during the build phase

  • Install ios-sim via Homebrew

      brew install ios-sim
    
  • Run ios-sim from a script in the test target

      RUN_UNIT_TEST_WITH_IOS_SIM=YES
      if [ "$RUN_UNIT_TEST_WITH_IOS_SIM" = "YES" ]; then
    

test_bundle_path="$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.$WRAPPER_EXTENSION"

@SQiShER
SQiShER / README.md
Created December 17, 2015 16:13
Delete unused Docker images

In theory it shouldn't be a problem to run docker rmi on images that are currently in use, as Docker will simply skip them.

In practice this doesn't seem to be bulletproof. On more than one occasion this caused weird problems, so I prefer to only run rmi for images that I know, are not in use.

Here's the command I use to do so:

docker rmi $(docker inspect -f '{{.Image}}' `docker ps -a -q --no-trunc` | grep -v -f - <(docker images -q --no-trunc))

I'm afraid the paths you are storing in MongoDB won't be very useful, since they are simply the default toString() representation of the referenced collection item. In order to use this path to access the property via java-object-diff, you'd need to be able to deserialize it to an actual instance of an object that has the same identity (equals == true) as the one you want to reference.

There are ways to do that, like writing a custom serializer for the PropertyPath to serialize a deserializable version of the reference item, but that leads to pretty verbose JSON and is rather fragile.

I personally don't recommend storing the diff in a database, but rather compare two document versions on demand. Depending on your scenario that may or may not cause performance issues. If it does, there are usually ways to cache the information you actually need, without storing the entire diff in the database.

I once had the same problem when I tried to generate a Github-like activity stream. I first approached it by stor

@SQiShER
SQiShER / docker_stats_with_names.sh
Last active May 5, 2020 07:35
Docker stats with Container Names instead of IDs
docker stats $(docker inspect -f '{{.Name}}' $(docker ps -q) | cut -c 2-)
@SQiShER
SQiShER / URLConnection.h
Last active July 16, 2020 10:51
Here is my solution for a better synchronous NSURLConnection. Although asynchronous NSURLConnections are usually a good way to go, sometimes there is just no way around waiting (and blocking) until a request finished. NSURLConnection offers a method to perform synchronous requests, but it is far from perfect and has some serious flaws. In my cas…
#import <Foundation/Foundation.h>
@interface URLConnection : NSObject <NSURLConnectionDataDelegate, NSURLConnectionDelegate>
+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request
returningResponse:(NSURLResponse **)response
error:(NSError **)error;
@end