Skip to content

Instantly share code, notes, and snippets.

@bricklife
bricklife / CollectionViewController.swift
Last active October 28, 2023 10:26
UITapGestureRecognizer in UICollectionView
//
// CollectionViewController.swift
// CollectionViewTouch
//
// Created by ooba on 30/01/2018.
// Copyright © 2018 ooba. All rights reserved.
//
import UIKit
@bricklife
bricklife / LEGO SPIKE Prime JSON command examples.md
Last active June 15, 2023 11:55
LEGO SPIKE Prime JSON command examples

System

{"i":"EMWW","m":"get_firmware_info","p":{}}
{"m":"trigger_current_state","p":{}}
{"m":"program_modechange","p":{"mode":"play"}} // "mode": "play" or "download"
{"i":"ESGe","m":"set_hub_name","p":{"name":"U1BJS0U="}} // "name": Base64 string

Motor

@bricklife
bricklife / SPIKE_Prime_REPL.txt
Last active January 18, 2023 22:05
REPL mode on LEGO Education SPIKE Prime hub
MicroPython v1.9.4-1146-gca9944357 on 2019-10-03; LEGO Technic Large Hub with STM32F413xx
Type "help()" for more information.
>>> help()
Welcome to MicroPython!
For online help please visit http://micropython.org/help/.
Quick overview of commands for the board:
hub.info() -- print some general information
hub.status() -- print sensor data
@bricklife
bricklife / vscode-spike-extension-test.py
Last active October 18, 2022 00:51
A sample code of `Python (advanced)` for lego-spikeprime-mindstorms-vscode
# LEGO type:advanced slot:0 autostart
from runtime.virtualmachine import VirtualMachine # Needed for newer hub versions (3.1.43+)
import hub
from util.rotation import rotate_hub_display_to_value
rotates = ["1", "3", "4", "2"]
rotate_index = 0
async def on_left_button_pressed(vm, stack):
print("Left button pressed")
//
// ViewController.swift
// WebSocketInjection
//
// Created by Shinichiro Oba on 2021/03/18.
//
import UIKit
import WebKit
@bricklife
bricklife / ViewController.swift
Created March 8, 2018 01:45
UIPanGestureRecognizer on UIScrollView
//
// ViewController.swift
// PanOnScroll
//
// Created by Shinichiro Oba on 2018/03/08.
// Copyright © 2018 bricklife.com. All rights reserved.
//
import UIKit
@bricklife
bricklife / lldb-plugin-curl.py
Created January 13, 2017 08:10
LLDB Plugin - curl
#!/usr/bin/env python
import lldb
def process(debugger, command, result, internal_dict):
lldb.debugger.HandleCommand("""
expr -l swift --
func $process(URLRequest: NSURLRequest) {
func curl(URLRequest: NSURLRequest) -> String {
guard let URLString = URLRequest.URL?.absoluteString else {
@bricklife
bricklife / main.py
Last active July 4, 2020 22:32
Autonomous running train in Pybricks
from pybricks.hubs import CityHub
from pybricks.pupdevices import DCMotor, ColorDistanceSensor
from pybricks.parameters import Port, Color
from pybricks.tools import wait
hub = CityHub()
motor = DCMotor(Port.A)
color_sensor = ColorDistanceSensor(Port.B)
def wait_for_color(color):
@bricklife
bricklife / spike_send.py
Created May 21, 2020 07:01
Send command to SPIKE from EV3
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.tools import wait
from pybricks.parameters import Button
from connection import SpikePrimeStreamReader
# Add send_command method into SpikePrimeStreamReader class
def send_command(self, command):
self.sock.send((command + '\r').encode())
#include <BleKeyboard.h> // https://github.com/T-vK/ESP32-BLE-Keyboard
BleKeyboard bleKeyboard;
bool pressing = false;
void setup() {
pinMode(25, INPUT_PULLUP); // A1 pin
bleKeyboard.begin();
}