Skip to content

Instantly share code, notes, and snippets.

View behrangsa's full-sized avatar
💾

Behrang Saeedzadeh behrangsa

💾
View GitHub Profile
@behrangsa
behrangsa / a-good-test-case.md
Created June 23, 2019 03:35
A good test case
@Test
public void showProject_shouldReturnAccessDenied_forUnauthenticatedUser() {
    // Given an unauthenticated get project request
    HttpEntity request = unauthenticatedRequest("GET /projects/1");

    // When the request is handled by the application
    ResponseEntity<ErrorResponse> response = handleRequest(request);

    // Then a forbidden response should be returned
/*-----------------------------------------------------------*/
/*--- A block-sorting, lossless compressor bzip.c ---*/
/*-----------------------------------------------------------*/
/*--
This program is BZIP, a lossless, block-sorting data compressor,
version 0.21, dated 25-August-1996.
Copyright (C) 1996 by Julian Seward.
Department of Computer Science, University of Manchester,
@behrangsa
behrangsa / sample.xsd
Created March 31, 2019 05:55
Sample XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="http://example.com"
xmlns:mstns="http://example.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
targetNamespace="http://example.com"
elementFormDefault="qualified" id="Example">
<xs:element name="Example_Parent">
<xs:complexType>
<xs:choice>
@behrangsa
behrangsa / LinkShortnerTransformer.java
Created March 31, 2014 11:22
A custom Sling Transformer for Adobe CQ 5 (AEM) that converts long URLs to short URLs
public class LinkShortnerTransformer extends AbstractSAXPipe implements Transformer {
private static final Logger log = LoggerFactory.getLogger(SitesmartRewriterTransformer.class);
private SlingHttpServletRequest httpRequest;
private static final String ATT_NAME = "href";
private static final String EL_NAME = "a";
public SitesmartRewriterTransformer() {
@behrangsa
behrangsa / self-signed-certificate-with-custom-ca.md
Created November 10, 2018 14:30 — forked from fntlnz/self-signed-certificate-with-custom-ca.md
Self Signed Certificate with Custom Root CA

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
"UserData": {
"Fn::Base64": { "Fn::Join":["", [
"#!/bin/bash -ex\n",
"apt-get update\n",
"apt-get -y install python-setuptools\n",
"mkdir aws-cfn-bootstrap-latest\n",
"curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1\n",
"easy_install aws-cfn-bootstrap-latest\n",
"/usr/local/bin/cfn-init --stack ", { "Ref":"AWS::StackName" }, " --resource WebServer", " --region ", { "Ref": "AWS::Region" }, "\n",
"\n",
@behrangsa
behrangsa / java-kotling.md
Last active January 21, 2018 13:56
Java vs Kotlin

Here are two examples:

Example 1

In version 3.1.4 of the RabbitMQ client for Java, Connection does not implement Closeable so you can't use try-with-resources when creating a new connection.

You can't do this either:

@Data
@Component
@ConfigurationProperties(prefix = "sample")
@Validated
public class SampleProperties {
@NotNull
private String sample1;
}
@behrangsa
behrangsa / 01 - home.js
Last active October 7, 2017 12:36
Stuck implementing Cognito Federated Authentication for a Web App using Lambda, API Gateway, and Twitter
module.exports.handler = function (event, context, callback) {
let body = `
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Serverless Home</title>
<style>
.hidden {