Skip to content

Instantly share code, notes, and snippets.

View alana-mullen's full-sized avatar

Alana Mullen alana-mullen

  • Preston, UK
View GitHub Profile
@alana-mullen
alana-mullen / bloc_ext.dart
Created November 3, 2023 01:36
Flutter extension for BLoC to reset to initial state
import 'package:flutter_bloc/flutter_bloc.dart';
extension BlocReset on Bloc {
void reset(dynamic initialState) {
emit(initialState);
}
}
@alana-mullen
alana-mullen / main.dart
Last active December 20, 2023 02:16
Flutter Adaptive AlertDialog
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Adaptive AlertDialog Demo',
debugShowCheckedModeBanner: false,
@alana-mullen
alana-mullen / ListExt.kt
Created May 6, 2022 12:11
Kotlin extension to return the first and last items from a List
/**
* Return the first and last items from a List
*/
fun <T> List<T>.ends(): List<T> {
if (this.size > 1) return this.take(1) + this.takeLast(1)
return this
}
@alana-mullen
alana-mullen / TimeDatePickers.kt
Last active July 18, 2022 14:46
Material TimeDate Pickers for Jetpack Compose
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import androidx.core.util.component1
import androidx.core.util.component2
import androidx.fragment.app.DialogFragment
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.timepicker.MaterialTimePicker
/**
* Time and Date Pickers for Jetpack Compose.
@alana-mullen
alana-mullen / ReconcileHelper.kt
Created June 8, 2020 04:07
Kotlin Playground - Display which numbers are in array 1, but not array 2
// My solution to: https://pl.kotl.in/Q1PY9OvAu
//
// Write a function called "reconcileHelper" that processes two arrays of integers.
// Each array will have only distinct numbers (no repeats of the same integer in
// the same array), and the arrays are not sorted.
// Your job is to find out which numbers are in array 1, but not array 2,
// and which numbers are in array 2, but not in array 1.
// Your function should return a string formatted as so:
// "Numbers in array 1 that aren't in array 2:
@alana-mullen
alana-mullen / ConnectivityExtension.kt
Created January 16, 2020 00:28
Android Kotlin extension to check network connectivity
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
val Context.isConnected: Boolean
get() {
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
@alana-mullen
alana-mullen / SwipeRefreshLayoutExt.kt
Created October 18, 2019 16:14
SwipeRefreshLayout Kotlin extensions
package uk.co.thewirelessguy.thewirelessguy.extensions
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
fun SwipeRefreshLayout?.start() {
this?.apply {
isRefreshing = true
isEnabled = false
}
}
@alana-mullen
alana-mullen / VerticalTextView.kt
Created October 15, 2019 00:26
VerticalTextView that extends AppCompatTextView
package uk.co.thewirelessguy.thewirelessguy.widget
import android.content.Context
import android.graphics.Canvas
import android.text.BoringLayout
import android.text.Layout
import android.text.TextUtils
import android.util.AttributeSet
import android.view.Gravity
import androidx.appcompat.widget.AppCompatTextView
@alana-mullen
alana-mullen / create_admin_user.php
Created March 20, 2018 16:43
Create new Magento admin user programmatically. Edit and add the php file below to the root of your Magento folder. Run it in the browser and the user will be created.
<?php
# Create new Magento admin user programmatically.
require_once('./app/Mage.php');
umask(0);
Mage::app();
try {
$user = Mage::getModel('admin/user')
->setData(array(
'username' => 'admin1',
@alana-mullen
alana-mullen / getAppIcon.swift
Created March 14, 2017 03:07
Use current iOS app icon with UIImageView in Swift 3
//
// GetAppIcon.swift
//
// Get the AppIcon from Assets and return it as a UIImage
// Created by Stephen Mullen
//
import UIKit
func getAppIcon() -> UIImage {