Skip to content

Instantly share code, notes, and snippets.

View deleteman's full-sized avatar

Fernando Doglio deleteman

View GitHub Profile
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)
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) {
while(suffixes.length > 0) {
createTree(tree)
}
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]] = "*"
function getAllSortedSuffixes(w) {
let suffixes = []
for(let i = 0; i < w.length; i++) {
suffixes.push(w.slice(i))
}
return suffixes.sort()
}
let tree = {}
useEffect(() => {
listen('new-todo', () => {
inputRef.current.focus()
})
}, [])
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();
}
tauri::Builder::default()
.menu(menu)
.run(tauri::generate_context!())
.expect("error while running tauri application");
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);
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()