Skip to content

Instantly share code, notes, and snippets.

@rock3m
rock3m / RerenderedView.swift
Last active July 19, 2022 20:00
Re-render View
struct WorkHistoryView: View {
@FetchRequest(sortDescriptors: [SortDescriptor(\.createdAt, order: .reverse)])
private var historyEntries: FetchedResults<WorkHistoryEntry>
@State var refreshCounter = 0 // Use this state var to trigger the re-rendering of the list
var body: some View {
List {
ForEach(historyEntries) { historyEntry in
WorkHistoryEntryView(historyEntry: historyEntry, refreshCounter: refreshCounter)
@rock3m
rock3m / WorkHistoryView.swift
Last active July 18, 2022 22:50
Example of using SectionedFetchQuery
struct WorkHistoryView: View {
@SectionedFetchRequest<String, WorkHistoryEntry>(
sectionIdentifier: \.createdAtDate,
sortDescriptors: [SortDescriptor(\.createdAt, order: .reverse)]
)
private var historyEntrySections: SectionedFetchResults<String, WorkHistoryEntry>
var body: some View {
List {
ForEach(historyEntrySections) { historyEntrySection in
@rock3m
rock3m / example.gs
Created March 31, 2022 19:21
An Example of Pulling Twitter Followers using Apps Script
var sheetName = "_Example";
var screenName = "imgracehuang";
function populateFollowerCount() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
var response = fetch("https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=" + screenName);
var followerCount;
if (response && response[0]) {
followerCount = response[0].followers_count
Ticker Cap Size Y2020 Performance 2021-01 Performance (Actual) 2021-01 Performance (In Theory)
SPWR Mid Cap 402.06% 82.71% 107.73%
FLGT Small Cap 303.88% 68.03% 103.56%
EXPI Mid Cap 457.11% 63.61% 68.68%
MSTR Mid Cap 172.42% 26.64% 48.27%
CMBM Small Cap 186.96% 40.11% 45.83%
TCS Small Cap 126.07% 23.32% 42.87%
STAA Mid Cap 125.25% 25.78% 28.77%
CLNE Small Cap 235.90% 9.02% 28.68%
REGI Mid Cap 162.78% 7.35% 25.81%
// Create a dictionary for all the unique words (one … ten, eleven … nineteen, twenty, thirty, forty, … ninty)
var WORD_DICT = {
0: "",
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
var express = require('express');
var app = express();
app.use(express.bodyParser());
app.get('/is-timer-on', function(req, res) {
var hours = new Date().getHours() - 8;
if (hours >= 20 || hours <=7) {
res.send("false " + hours);
} else {
@rock3m
rock3m / init.lua
Created December 22, 2015 06:05
Lua script for Building a kid’s sleep training clock using NodeMCU and Parse (Prototype)
function changeLED(on)
pin = 1
gpio.mode(pin,gpio.OUTPUT)
if on == true
then gpio.write(pin,gpio.HIGH) end
if on == false
then gpio.write(pin,gpio.LOW) end
end
changeLED(false)
@rock3m
rock3m / lm35-to-thingspeak.lua
Last active March 25, 2018 00:58
Detecting the indoor temperature using LM35, and send the periodic recordings to ThingSpeak via WiFi. See project details at https://medium.com/grace-learns-iot/day-7-monitoring-home-temperature-on-the-internet-26c175ee7200
--- Config
SSID = "YOUR_WIFI_NAME"
PASSWORD = "YOUR_WIFI_PASSWORD"
TIMEOUT = 30000000 -- 30s
--- Station modes
STAMODE = {
STATION_IDLE = 0,
STATION_CONNECTING = 1,
STATION_WRONG_PASSWORD = 2,