Skip to content

Instantly share code, notes, and snippets.

modules = [
{ date "+DATE: %d/%m/%y TIME: %H:%M:%S" }
{ acpi -b | cut -d ',' -f 2 | cut -d ' ' -f 2 }
]
while $true {
for m $modules { $m } |
xsetroot -name (joins ' ')
sleep 1
}
@xiaq
xiaq / README.md
Created February 1, 2019 02:30
SCRIPT-8
# Intersection of two character sets.
# ${var//pattern} removes all matches of pattern in $var.
# By removing all characters that are not in s2 from s1, you obtain the intersection.
s1=abcd
s2=axyz
echo ${s1//[^s2]}
# Determine if a word is in a space-separated list
case " $haystack " in
*" $needle "*)
package main
import (
"bufio"
"bytes"
"io"
"os"
"unicode"
)
# Pressing Enter when the command is empty shows you the last command.
# You can press Enter again to execute.
edit:insert:binding[Enter] = {
if (eq $edit:current-command '') {
edit:history:start
} else {
edit:smart-enter
}
}
@xiaq
xiaq / issuebot.elv
Last active March 13, 2018 21:35
An IRC bot that expands mentions of GitHub issues
#!/usr/bin/env elvish
# Run with: socat OPENSSL:irc.freenode.net:6697 EXEC:./issuebot
use re
api-base = https://api.github.com/repos/elves/elvish/issues
web-base = https://github.com/elves/elvish/issues
echo "NICK ghhasher"
echo "USER ghhasher 0 * :GitHub Issue Linkifier"
# I have a type that used to be called "EvalCtx" but now called "Frame".
# The gorename tool can make a sweeping change of all references to EvalCtx,
# but I'm still left with many arguments and method receivers called "ec".
# With the type name changed, they now look like:
#
# func f(ec *Frame, ...)
#
# I want to do a batch rename of all those variables as well. Here is a really
# simple Elvish script to do it.
@xiaq
xiaq / prompt.go
Last active February 22, 2018 01:20
// This code illustrates a concurrent prompt updating algorithm with the following properties:
// 1. Non-parallelism: No two instances of the prompt update function is run in parallel.
// 2. Freshness: after an input, the prompt will always updated at early as possible.
// 3. Economy: Prompt is only updated when new inputs have arrived.
func updatePrompt(req <-chan struct{}) {
for range req {
update()
}
}
// The following function does not work, because i is allocated on the stack, so a pointer to it becomes
// invalid after the function call returns.
int *f() {
int i = 20;
return &i;
}
// Hence, to return a int pointer, the space must be allocated on the heap:
int *g() {
int *p = malloc(sizeof(int));
@xiaq
xiaq / 394-parser.java
Last active January 16, 2018 22:46
Solution to leetcode 394, by implementing a parser
import java.util.List;
import java.util.LinkedList;
import java.lang.StringBuilder;
class Solution {
interface Node {
void write(StringBuilder sb);
}
// SimpleNode is a sequence of non-special characters, like "abc".