Skip to content

Instantly share code, notes, and snippets.

@dinh
dinh / custom-web-search-llm.js
Created May 22, 2023 20:22 — forked from npilk/custom-web-search-llm.js
Cloudflare Worker script to automatically route queries to search engines or an LLM based on their content.
// Cloudflare Worker script to automatically redirect search queries based on trigger words
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
// status code for redirect response; need something that won't cache
var statuscode = 303
// defining base URLs for search engines
@nilsandrey
nilsandrey / name-shortening functions.js
Last active May 2, 2024 02:46
Name-shortening functions from Hacker News own JS for web site
// From yesenadam at https://news.ycombinator.com/item?id=23590848
function $(id) { return document.getElementById(id); }
function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] }
function byTag (el, tg) { return el ? el.getElementsByTagName(tg) : [] }
function allof (cl) { return byClass(document, cl) }
function hasClass (el, cl) { var a = el.className.split(' '); return afind(cl, a) }
function addClass (el, cl) { if (el) { var a = el.className.split(' '); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(' ')}} }
function remClass (el, cl) { if (el) { var a = el.className.split(' '); arem(a, cl); el.className = a.join(' ') } }
function html (el) { return el ? el.innerHTML : null; }
@dinh
dinh / name-shortening functions.js
Created February 18, 2023 12:40 — forked from nilsandrey/name-shortening functions.js
Name-shortening functions from Hacker News own JS for web site
// From yesenadam at https://news.ycombinator.com/item?id=23590848
function $(id) { return document.getElementById(id); }
function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] }
function byTag (el, tg) { return el ? el.getElementsByTagName(tg) : [] }
function allof (cl) { return byClass(document, cl) }
function hasClass (el, cl) { var a = el.className.split(' '); return afind(cl, a) }
function addClass (el, cl) { if (el) { var a = el.className.split(' '); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(' ')}} }
function remClass (el, cl) { if (el) { var a = el.className.split(' '); arem(a, cl); el.className = a.join(' ') } }
function html (el) { return el ? el.innerHTML : null; }
@dinh
dinh / 00-OozieWorkflowJavaMapReduceAction
Created February 23, 2023 20:19 — forked from airawat/00-OozieWorkflowJavaMapReduceAction
Oozie workflow application with a Java Mapreduce action that parses syslog generated log files and generates a report Gist includes sample data, all workflow components, java mapreduce program code, commands - hdfs and Oozie
This gist includes components of a oozie workflow - scripts/code, sample data
and commands; Oozie actions covered: java mapreduce action; Oozie controls
covered: start, kill, end; The java program uses regex to parse the logs, and
also extracts the path of the mapper input directory path and includes in the
key emitted.
Note: The reducer can be specified as a combiner as well.
Usecase
-------
Quick little visual explainers on the topics and things I tend to forget
@jr-codes
jr-codes / include-callback.js
Last active May 2, 2024 02:45
include(): JavaScript function for dynamically including a CSS or JS file on a page
/**
* Includes the CSS or JS file into the head of the page.
*
* Examples:
* include('http://example.com/script.js')
* include('http://example.com/style.css')
* include('http://example.com/script.php', 'js')
* @param {string} url URL of the CSS or JS file
* @param {string} [type] 'css' or 'js' to specify the type of file.
* This parameter is optional, but it should be
@jr-codes
jr-codes / gcal-kill-tasks.user.js
Created August 29, 2012 05:07
Google Calendar Tasks Killer
// ==UserScript==
// @name Google Calendar Tasks Killer
// @namespace http://zarjay.net/
// @description Removes the "Tasks" item from the "My Calendar" section of Google Calendar
// @match https://www.google.com/calendar/*
// @version 1.0
// ==/UserScript==
// Removes the "Tasks" item from "My Calendar"
@jr-codes
jr-codes / u.user.js
Last active May 2, 2024 02:45
u.js userscript
// ==UserScript==
// @name u.js
// @namespace http://zarjay.net/
// @description Utility functions for browser console ninjas
// @include *
// @version 0.28
// ==/UserScript==
exec(function() {
// Current version of u.js
@jr-codes
jr-codes / open-json.user.js
Created August 19, 2016 21:32
Userscript for opening JSON in the Chrome JSON Viewer extension
// ==UserScript==
// @name Open JSON
// @version 1.0.0
// @description Opens JSON in a json-viewer window
// @match http://*/*
// @match https://*/*
// ==/UserScript==
const exec = fn => {
const script = document.createElement('script');
@jr-codes
jr-codes / input.scss
Created June 29, 2021 18:14
Generated by SassMeister.com.
@mixin build-class($class, $min: 0, $max: 100, $orientation: 'small', $type: 'normal') {
.luna-#{$class}-#{$orientation} {
color: blue;
}
}
@include build-class('test', 'large');