Skip to content

Instantly share code, notes, and snippets.

View maxencehenneron's full-sized avatar

Maxence Henneron maxencehenneron

View GitHub Profile
@maxencehenneron
maxencehenneron / use-reactive-query.ts
Last active March 1, 2024 20:01
Defines a custom React hook useReactiveQuery that rerenders a component when the result of a SQLite query changes. It's designed to work with the drizzle-orm and expo-sqlite libraries
import { useEffect, useState } from "react";
import { AnySQLiteTable, getTableConfig } from "drizzle-orm/sqlite-core";
import { addDatabaseChangeListener } from "expo-sqlite/next";
import { SQLiteSyncRelationalQuery } from "drizzle-orm/sqlite-core/query-builders/query";
/**
* A helper hook that rerenders the component when the result of a query changes
* @param query the query to run
* @param dependencies the tables that the query depends on
* @param rowId the row id to watch for changes
import { firebase } from '@react-native-firebase/analytics';
export default {
logEvent: (
name: string,
params?: { [key: string]: any },
): Promise<void> => firebase.analytics().logEvent(name, params),
};
@maxencehenneron
maxencehenneron / gist:6812863
Last active December 24, 2015 14:29
Get ram usage in % and load average
def get_load_average
load_avg = nil
File.open('/proc/loadavg') {|f|
load_avg = Float(f.readline.split(' ')[2])
}
load_avg
end
def get_ram_usage
mem_total = mem_free = mem_cached = nil;
require 'daemons'
# This file will contain all System calls by the program.
# (ie : Launching a programm, monitoring it)
# Returns the pid of the child that executes the cmd
module Monitor
module System
extend self
def daemonize(cmd, options = {})