Skip to content

Instantly share code, notes, and snippets.

@chrissearle
chrissearle / asyncFactory.js
Created September 24, 2014 19:10
AngularJS - service to call http async and return data to controller - is there a better way than exposing the promise itself back to the controller?
.factory('someService', ['$http', function ($http) {
return {
async: function () {
return $http.get('someUrl').then(function (response) {
return response.data;
});
}
};
}]).controller('someController', ['$scope', 'someService', function ($scope, someService) {
someService.async().then(function (d) {
@chrissearle
chrissearle / Playground.swift
Last active October 7, 2016 17:48
Extending enums to get a usable description method
import UIKit
// Enum copied into playground directly from DJI third party SDK
public enum DJICameraExposureMode : UInt {
case Program
case Shutter
case Aperture
case Manual
case Unknown
---
version: '3'
services:
zookeeper:
image: zookeeper
ports:
- 2181:2181
kafka:
image: confluentinc/cp-kafka
ports:
@chrissearle
chrissearle / SummerStudents.pdf
Last active July 6, 2021 12:43
Spring - Summer Students
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chrissearle
chrissearle / zip_directories_to_xcassets.zsh
Created October 20, 2021 20:52
Create xcassets from three directories of PNG images - 1x, 2x and 3x
#!/bin/zsh
# Assumes you start with three directories of images in png format with the same name - 1x, 2x and 3x
# Call with four params
# zip_directories_to_xcassets.zsh name_of_asset_file directory_of_1x_pngs directory_of_2x_pngs directory_of_3x_pngs
ASSETS_DIR=$1.xcassets
D1=$2
D2=$3
D3=$4
@chrissearle
chrissearle / Convert.java
Last active November 23, 2021 07:22
Convert PNG To RGB565 For Adafruit_GFX TFT
/**
* Could't get adafruit's image reader working on Teensy 4.1 - doesn't seem to be compatible with
* Teensy's version of the SD card library
*
* But - the TFT object has this method:
*
* void Adafruit_GFX::drawRGBBitmap(
* int16_t x,
* int16_t y,
* uint16_t * bitmap,
@chrissearle
chrissearle / Convert.java
Created November 25, 2021 08:43
Convert png to rgb565
public class Convert {
public static void main(String[] args) {
String pngFile = args[0];
String datFile = args[1];
try {
BufferedImage image = ImageIO.read(new File(pngFile));
try (
LittleEndianDataOutputStream outputStream = new LittleEndianDataOutputStream(new FileOutputStream(datFile))
@chrissearle
chrissearle / Controller.kt
Last active January 5, 2022 13:37
Kotlin coroutine spring boot MVC - Controller vs DSL
@RestController
class Controller(val service: SomeService) {
@GetMapping("/something")
fun all() = service.all()
@PostMapping("/something")
suspend fun save(@RequestBody something: CreateDTO) = service.create(something)
@PutMapping("/something/{id}")
suspend fun update(@PathVariable id: Long, @RequestBody updates: UpdateDTO) = service.update(id, updates)
@chrissearle
chrissearle / how-to-start-colima-automatically-on-macos.md
Created March 15, 2023 17:01 — forked from fardjad/how-to-start-colima-automatically-on-macos.md
[How to start Colima automatically on macOS] Instructions for starting Colima automatically on macOS similar to Docker Desktop #macos #colima #docker

Steps

  1. Allow colima start to run without password:
cat <<-EOF | sudo tee /private/etc/sudoers.d/colima
%admin ALL=NOPASSWD: /bin/rm -rf /var/run/docker.sock
%admin ALL=NOPASSWD: /bin/ln -s $HOME/.colima/docker.sock /var/run/docker.sock
EOF
<html>
<head>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"