Skip to content

Instantly share code, notes, and snippets.

View Mattamorphic's full-sized avatar
:shipit:
Building things, and making stuff

Matt B Mattamorphic

:shipit:
Building things, and making stuff
View GitHub Profile
@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):
@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 / 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 / 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 / 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 / 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 / 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 / publish.yml
Last active August 22, 2020 18:34
NPM Publish GitHub Package Registry
name: Deploy package to GitHub package registry
on:
pull_request:
branches:
- master
push:
branches:
- master
jobs:
build:
@Mattamorphic
Mattamorphic / account.ts
Created September 24, 2019 08:02
Example Typescript Webhooks
export enum AccountType {
USER = 'User',
ORGANIZATION = 'Organization'
}
export interface Account {
login: string;
id: number;
node_id: string;
avatar_url: string;
@Mattamorphic
Mattamorphic / implementation.py
Last active October 1, 2019 16:24
Gradient Descent Example Python
# Given f(x) = x**4 - 3**3 + 2 = f1(x) = 4x**3 - 9**2
# lets start at x = 6
curr_x = 6
gamma = 0.001
precision = 0.0000001
step_size = 1
max_iterations = 1000
i = 0
df = lambda x: (4 * x**3) - (9**2)