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 / metrics.diff
Last active July 13, 2021 19:17
HAProxy Exporter vs. Built-in Metrics
go_gc_duration_seconds | haproxy_backend_active_servers
go_gc_duration_seconds_count | haproxy_backend_backup_servers
go_gc_duration_seconds_sum <
go_goroutines <
go_info <
go_memstats_alloc_bytes <
go_memstats_alloc_bytes_total <
go_memstats_buck_hash_sys_bytes <
go_memstats_frees_total <
go_memstats_gc_cpu_fraction <
@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))
@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 / 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 / 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 / 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 / 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
@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"

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 / UpdateEnvironmentPlist.sh
Created May 17, 2012 16:46
Two simple commands to resolve problems with Maven installed via Homebrew
defaults write ~/.MacOSX/environment.plist M2_HOME `brew --prefix maven`/libexec
defaults write ~/.MacOSX/environment.plist M2 `brew --prefix maven`/libexec/bin