Skip to content

Instantly share code, notes, and snippets.

Avatar

Jack Mahoney jackmahoney

View GitHub Profile
@jackmahoney
jackmahoney / flatten.ts
Created Jul 7, 2020
Flatten an array of arrays or map of arrays in Typescript single liner
View flatten.ts
/**
* Flatten a map of arrays or array of arrays to a single array
* @param t
*/
export function flatten<T>(t: Array<Array<T>> | { [p: string]: Array<T> }): Array<T> {
return Object.values(t).reduce((mem, val) => [...mem, ...val], [])
}
View fetch-email-php-example.php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use PHPUnit\Framework\TestCase;
/**
* This testsuite demonstrates how to use MailSlurp Email API Client in PHP
*
* MailSlurp let's you create real email addresses in PHP. You can then send and receive emails
* and attachments in PHP applications and tests.
@jackmahoney
jackmahoney / test-oauth2-verification-email-code.spec.js
Last active Feb 18, 2020
MailSlurp javascript client example
View test-oauth2-verification-email-code.spec.js
// import an apiKey and the official js client
const apiKey = require("./config.json").apiKey;
const MailSlurpClient = require("mailslurp-client");
// instantiate a client for the inbox endpoints
const api = new MailSlurpClient.InboxcontrollerApi();
// test the authentication flow on www.mailslurp.com
// using Cypress test runenr
describe("Emaile2e.com user signup", () => {
@jackmahoney
jackmahoney / debug-play-framework-test-intellij.md
Created Mar 19, 2015
Debug Play Framework 2.x unit test in IntelliJ
View debug-play-framework-test-intellij.md

In build.sbt add the following lines:

Keys.fork in Test := false
parallelExecution in Test := false
  • Start the play console in debug mode $ play debug.
  • Create a RemoteDebug run configuration in IntelliJ. This is only a debugger, not a compiler.
  • Run this configuration listening on port 9999.
@jackmahoney
jackmahoney / config.js
Last active Apr 5, 2019
Vuepress Markdown Variable substitution
View config.js
// inside config.js extend webpack so that `__var_name__` is replaced with value of `config[var_name]`
// relies on npm install string-replace-loader
{
configureWebpack(config) {
config.resolve.alias["@"] = path.join(__dirname, "/theme");
config.resolve.alias["~"] = path.join(__dirname, "/public");
if (process.env.NODE_ENV === "production") {
const mappings = Object.keys(config).map(key => {
return { search: `__${key}__`, replace: config[key] }
})
@jackmahoney
jackmahoney / ecs.tf
Last active Sep 25, 2018
ecs-cluster-service-task-definition
View ecs.tf
/*
ecs cluster and service definitions
*/
resource "aws_ecs_cluster" "ecs" {
name = "${var.name}-ecs"
}
/*
define ecs task for this app
*/
@jackmahoney
jackmahoney / Static typeface
Created Feb 24, 2014
Set custom font on an android custom textview. Untested code, be sure to test.
View Static typeface
public class TextHelper{
private static TypeFace typeface = null;
public static void setTypeface(Context context, TextView textview){
if(this.typeface == null){
this.typeface = Typeface.createFromAsset(context.getAssets(), "Helvetica_Neue.ttf");
}
textview.setTypeface(face);
}
@jackmahoney
jackmahoney / script.js
Created Oct 26, 2016
Scrape digitalagencynetwork.com
View script.js
// execute in chrome snippets section on a page such as http://digitalagencynetwork.com/agencies/melbourne/
// copy result into a csv file an voila
var $ = jQuery;
var results = [];
$('.entry .threecol-two.last').each(function(){
var title = $(this).find('h3').text();
var address = $(this).find('a').attr('href');
var emailMatch = $(this).first('h6').text().match(/[\w\.]+@[\w\.]+/);
var email = emailMatch ? emailMatch[0] : 'unknown';
results.push([title,address,email].join(','));
@jackmahoney
jackmahoney / jm_wp_alc_med_access_ex_impl.php
Created Jul 31, 2012
Implementation of media access extension
View jm_wp_alc_med_access_ex_impl.php
<div class="clearfix">
<?php $metabox->the_field('cta-feature-img'); ?>
<?php $wpalchemy_media_access->setGroupName('cta-feature-img')->setInsertButtonLabel('Insert CTA Image')->setTab('type'); ?>
<p>
<span class="help">CTA Image - Please upload the Page CTA image at the dimensions: 280px x 146px</span>
<?php echo $wpalchemy_media_access->getField(array('name' => $metabox->get_the_name(), 'value' => $metabox->get_the_value())); ?>
<?php echo $wpalchemy_media_access->getButton(array('label' => 'Upload CTA Image')); ?>
<?php $metabox->the_field('cta-feature-img-meta'); ?>
<?php echo $wpalchemy_media_access->getMetaField(array('groupname'=>'cta-feature-img','name' => $metabox->get_the_name(), 'value' => $metabox->get_the_value())); ?>
@jackmahoney
jackmahoney / jm_wp_alchemy_media_access.php
Created Jul 31, 2012
Extension of WP_Alchemy mediaaccess class
View jm_wp_alchemy_media_access.php
<?php
include('MediaAccessBase.php');
/**
* @author Jack Mahoney
*/
class WPAlchemy_MediaAccess extends WPAlchemy_MediaAccess_Base{
public $meta_field_class_name = 'media-meta-field';
You can’t perform that action at this time.