Skip to content

Instantly share code, notes, and snippets.

View fzakaria's full-sized avatar

Farid Zakaria fzakaria

View GitHub Profile
@fzakaria
fzakaria / Base85.java
Created February 2, 2016 23:58
A simple Base85 / Ascii85 codec
/**
* A very simple class that helps encode/decode for Ascii85 / base85
* The version that is likely most similar that is implemented here would be the Adobe version.
* @see <a href="https://en.wikipedia.org/wiki/Ascii85">Ascii85</a>
*/
public class Base85 {
private final static int ASCII_SHIFT = 33;
@fzakaria
fzakaria / BigByteBuffer.java
Created August 23, 2017 23:30
A BufferFacade that wraps many ByteBuffers beyond the integer length
package casper.verification.struct;
import net.sf.kdgcommons.buffer.BufferFacade;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.util.function.Function;
public class BigByteBuffer implements BufferFacade {
@fzakaria
fzakaria / SpanMixin.java
Created November 17, 2017 18:55
Jaeger Span Jackson Mixin
import com.fasterxml.jackson.annotation.JsonProperty;
import com.uber.jaeger.Span;
import java.util.List;
import java.util.stream.Collectors;
/**
* Jackson mixin for defining how a {@link com.uber.jaeger.Span} gets turned into JSON
* This was built using the fixtures from Jaeger codebase --
* The usefulness of this class would be if as part of your infrastructure there are already ways to get log data
/**
* A very simple {@link Injector} and {@link Extractor} that use a {@link StringBuffer} as the transmission.
* This class <b>will only</b> transmit the {@link io.opentracing.SpanContext} without any baggage
* (that's why its simple).
*/
public class SimpleStringCodec implements Injector<StringBuffer> , Extractor<StringBuffer> {
@Override
public void inject(SpanContext spanContext, StringBuffer carrier) {
carrier.append(spanContext.contextAsString());
@fzakaria
fzakaria / jaeger_thrift.java
Created January 2, 2018 20:08
Jaeger reading / writing thrift from a file
import com.uber.jaeger.Span;
import com.uber.jaeger.Tracer;
import com.uber.jaeger.exceptions.SenderException;
import com.uber.jaeger.reporters.Reporter;
import com.uber.jaeger.samplers.ConstSampler;
import com.uber.jaeger.samplers.Sampler;
import com.uber.jaeger.senders.ThriftSender;
import com.uber.jaeger.thriftjava.Process;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
@fzakaria
fzakaria / https.java
Last active October 20, 2022 10:16
How to properly use an http client with a self signed certificate
/**
* Too many examples on the internet demonstrate using self-signed certificates by disabling hostname verification
or providing a weak TrustManager (i.e. SelfSignedTrustManager).
This example shows how to properly start a server & client in the same JVM where the client knows about the
generated self-signed certificate.
Also it's all done programmatically! Avoid using keytool and pulling in heavy dependencies like BouncyCastle!~
**/
public class SecureServerTest {
/**
@fzakaria
fzakaria / netty_tls_raw.java
Created December 28, 2018 08:14
Decrypt by hand TLS payload
public class Test {
@Test
public void testExtractMasterkeyWorksCorrectly() throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate();
SslContext serverContext = SslContextBuilder.forServer(cert.key(), cert.cert())
.sslProvider(SslProvider.OPENSSL).build();
final OpenSslEngine serverEngine =
(OpenSslEngine) serverContext.newEngine(UnpooledByteBufAllocator.DEFAULT);
class TestTable < Sequel::Model(:test_table)
def is_something?
self[:x] == 123
end
end
TestTable.where{ is_something? }

Keybase proof

I hereby claim:

  • I am fzakaria on github.
  • I am fzakaria (https://keybase.io/fzakaria) on keybase.
  • I have a public key whose fingerprint is 0D68 D1FD E13D EBD6 95B9 19B2 81FB F501 D1B2 32E7

To claim this, I am signing this object:

class RequestFilter
def initialize(app, tracer)
@app = app
@tracer = tracer
end
EXCLUDED_PATH_PREFIXES = %w[
...
].freeze