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 / README.md
Created September 9, 2021 08:36
Configuring create-react-app with typescript / css modules

How to configure create-react-app with typescript / css modules

  1. yarn create react-app app --template typescript
  2. cd app/
  3. yarn add -D typescript-plugin-css-modules
  4. In the compilerOptions of tsconfig.json add typescript-plugin-css-modulesplugin "plugins": [{ "name": "typescript-plugin-css-modules" }]
  5. touch src/global.d.ts
  6. Add the following to global.d.ts
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Mattamorphic
Mattamorphic / decompress_csv.py
Created April 15, 2021 05:57
Decompression PYthon
from io import StringIO
import csv
import gzip
with gzip.open(filename, mode="rt") as g:
csvobj = csv.reader(g)
for line in csvobj:
print(line)
@Mattamorphic
Mattamorphic / compress_csv.rb
Created April 15, 2021 05:56
Compression Rails
Tempfile.open(["#{Rails.root}/tmp/", ".csv"]) do |f|
# Write the batch to a csv file (cheaper than 5000 queries)
f = ActiveSupport::Gzip.compress(ModelDatum.where(model_id: 2).pluck(:id, :preprocessed_data).map(&:to_csv).join)
puts f.size()
puts ActiveSupport::Gzip.decompress(f)
end
@Mattamorphic
Mattamorphic / scikit-learn.py
Created March 29, 2021 16:57
Visualizing Decision Tree
# 1. Load the dataset
from sklearn.datasets import load_iris
iris = load_iris()
# 2. Select only the Petal length and Petal width features
#(easier to graph)
X = iris.data[:, 2:]# petal length and width
y = iris.target
# 3. Train our Decision Tree classifier on the Iris Dataset
from sklearn.tree import DecisionTreeClassifier
tree_clf = DecisionTreeClassifier(max_depth=2)
@Mattamorphic
Mattamorphic / MainActivity.java
Created October 24, 2020 15:06
Runtime permissions handling
package com.example.runtime_permissions;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
@Mattamorphic
Mattamorphic / AndroidManifest.xml
Created October 24, 2020 12:36
Example 034 (for API > 24)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example034">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
@Mattamorphic
Mattamorphic / test.rb
Last active April 28, 2020 10:06
Dry-Example
# frozen_string_literal: true
require "minitest/mock"
class MyJobTest < ActiveJob::TestCase
# Helper function to wrap mocking the :mymethod method
#
# expectations - Array of Procs/Lambdas that will be checked against the message
# argument that is passed to the :mymethod method in the MyModule::myclass
# object, all must return true.
@Mattamorphic
Mattamorphic / test.rb
Last active April 28, 2020 09:40
Non-Dry-Example
# frozen_string_literal: true
require "minitest/mock"
class MyJobTest < ActiveJob::TestCase
test "check job calls method" do
mock = Minitest::Mock.new
mock.expect :mymethod, nil do |id:, message:|
id.is_a?(Integer) &&
message.is_a?(String)
@Mattamorphic
Mattamorphic / README.md
Created February 14, 2020 08:54
Useful git commands

Sign commits on the current branch since the SHA (inclusive)

git rebase --exec 'git commit --amend --no-edit -n -S' -i SHA^