Skip to content

Instantly share code, notes, and snippets.

View Mattamorphic's full-sized avatar

Matt B Mattamorphic

View GitHub Profile
@Mattamorphic
Mattamorphic / build.gradle
Created August 22, 2019 12:48
MVN Package Gradle Example
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application
id 'application'
id 'maven-publish'
}
repositories {
@Mattamorphic
Mattamorphic / Example1.md
Last active June 29, 2020 14:53
GraphQL Pagination Example (v4)

Here is a GraphQL query to fetch my repositories

{
  user(login: "Mattamorphic") {
    repositories(first: 2) {
      edges {
        cursor
        node {
 name
@Mattamorphic
Mattamorphic / problem1.py
Created April 28, 2017 11:27
Project Eular Problem 1 in Python
# /bin/python3
import itertools # we'll need the unique combinations of multiples
'''
Calculate the sum of all multiples in a given total
Divide total by multiples to get the amount of multiples.
Then multiply this by the total plus the multiple and divie the result
by 2
:param int multiple The multiples to search for
@Mattamorphic
Mattamorphic / memTest.php
Last active February 5, 2017 11:25
Memory Usage / Time Testing PHP Hash Storing
<?php
/**
* This is tested in PHP 7.1
* As part of a system I'm looking to store a series of hashes, and look these up.
* There could be many hashes, and I don't need to use these, I just need to know if they exist.
*
* The following tests pit arrays against strings to see which is the fastest.
* I'll be searching for MTIzNDY5MTI1Njc4 which is the number 12345678 * 1000 base 64 encoded
**/
@Mattamorphic
Mattamorphic / multi_stripos.php
Created December 2, 2016 09:30
Multi-stripos with Array of Needles in Haystack and Optional Filtering
<?php
/**
* Perform an STRIPOS with multiple needles, and optionally filter the result to a bool
* @param string $haystack The string to search
* @param array $needles The array of needles to hunt for
* @param int $offset The offset to start at
* @param bool $filter Should we filter the result to a boolean?
*
* @return mixed
@Mattamorphic
Mattamorphic / optimised_file_read.php
Created October 20, 2016 11:51
Optimised CSV file reading with PJP
<?php
Class CSVHandle
{
const CHUNK_SIZE = 4096;
private $chunk = [];
private $buffer = '';
private $fp = null;
/**
@Mattamorphic
Mattamorphic / unzip_file_method.py
Last active October 14, 2015 16:52
Unzip files and return a list of the extracted files in Python
def unzip_file(self, path):
'''
Using a file path, unzip the file in to a directory of files returning a list of files in that folder
:param path, a string representing the location of the zip file (path/to/zip.zip)
:rtype list of files in decompressed folder
'''
import os
import zipfile
folder, ext = os.path.splitext(path)
if not os.path.exists(folder):