Skip to content

Instantly share code, notes, and snippets.

View deleteman's full-sized avatar

Fernando Doglio deleteman

View GitHub Profile
View search.js
function search(tree, word) {
let root = null
do{
root = Object.keys(tree).find( k => word.indexOf(k) == 0)
word = word.replace(root, "")
tree = tree[root]
} while(root)
View find-prefixes.js
function findPrefixes(words) {
let sample = words[0]
let currentSet = []
let lastCommonSet = []
let currentPrefix = "";
let lastValidPrefix = "";
for(let i = sample.length; i > 0; i--) {
currentPrefix = sample.slice(0, i)
currentSet = words.filter( w => w.indexOf(currentPrefix) == 0)
if(currentSet.length > 0 && currentSet.length > lastCommonSet.length) {
View main-loop.js
while(suffixes.length > 0) {
createTree(tree)
}
View create-tree.js
function createTree(tree) {
let ret = findPrefixes(suffixes)
suffixes = removeWordsFromList(ret.usedWords, suffixes)
root = ret.group.shift()
tree[root] = {pending: ret.group}
while(tree[root].pending.length > 0) {
ret = findPrefixes(tree[root].pending)
if(ret.group.length == 1) { //it's a leaf
tree[root][ret.group[0]] = "*"
View sorted-suffixes.js
function getAllSortedSuffixes(w) {
let suffixes = []
for(let i = 0; i < w.length; i++) {
suffixes.push(w.slice(i))
}
return suffixes.sort()
}
let tree = {}
View event-listener.js
useEffect(() => {
listen('new-todo', () => {
inputRef.current.focus()
})
}, [])
View menu-event.rs
tauri::Builder::default()
.menu(menu)
.on_menu_event(|event| {
match event.menu_item_id() {
"quit" => {
std::process::exit(0);
}
"new" => {
event.window().emit("new-todo", "").unwrap();
}
View builder.rs
tauri::Builder::default()
.menu(menu)
.run(tauri::generate_context!())
.expect("error while running tauri application");
View menu.rs
let new_todo = CustomMenuItem::new("new".to_string(), "New ToDo");
let close = CustomMenuItem::new("quit".to_string(), "Quit");
let submenu = Submenu::new("File", Menu::new().add_item(new_todo).add_item(close));
let menu = Menu::new()
.add_native_item(MenuItem::Copy)
.add_item(CustomMenuItem::new("hide", "Hide"))
.add_submenu(submenu);
View to-do.jsx
import React, { useEffect, useState, useRef } from 'react';
import Sentiment from 'sentiment';
import 'bootstrap/dist/css/bootstrap.min.css';
const sentiment = new Sentiment();
function TodoApp() {
const [todos, setTodos] = useState([]);
const [input, setInput] = useState('');
const inputRef = useRef()