Skip to content

Instantly share code, notes, and snippets.

View smac89's full-sized avatar

Nobleman smac89

View GitHub Profile
@smac89
smac89 / zsh-lazy.md
Last active August 4, 2023 05:56
ZSH lazy loading #zsh #lazy

The following is a function I use in my .zshrc file to achieve some form of lazy evaluation.

local function lazy_load() {
    local -xr thunk="$(cat)"
    # (u) removes duplicates
    local -xr triggers=(${(u)@})
    
    # Only if length of triggers is greater than zero
 # otherwise the function will immediately execute.
@smac89
smac89 / Unbound timer.md
Last active May 30, 2020 19:03
Create systemd timer from simple command

To create the timer described here

systemd-run --on-calendar='*-*-01 12:00:00' --unit='unbound-root-hints' \
--remain-after-exit --description='Update root hints for unbound' --property='Type=exec' \
--property='After=network.target' --timer-property='Persistent=true' \
--timer-property='RandomizedDelaySec=2s' --timer-property='AccuracySec=1us' \
/usr/bin/curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache
@smac89
smac89 / Restoring Sanity.md
Last active February 11, 2021 05:09
Linux Desktop User: Sane defaults

Being a Linux desktop user is not easy, but it doesn't have to be difficult.

Enabling persistent journals

This is especially useful for collecting logs of system issues.
@smac89
smac89 / StructuralSearch.md
Last active May 10, 2020 07:58
Structural search tips. #IntelliJ #idea

Find field references on an instance

In this example, we want to find places where one did:

someClass.someField

Where someClass is of the type fully.qualified.SomeClass

Find and replace field reference with method call
@smac89
smac89 / Instructions.md
Last active August 2, 2018 05:01
Teamspeak server setup on Linux Ubuntu 16.04. #teamspeak #server #ts3

Downloading teamspeak

Since the server will likely not have a UI, so the download must be done with a command

The command to download teamspeak (Find the most recent version and download instead):

wget -O teamspeak-server.tar.bz2 http://dl.4players.de/ts/releases/3.0.13.8/teamspeak3-server_linux_amd64-3.0.13.8.tar.bz2

Setting up teamspeak folder

@smac89
smac89 / SSHServerSetup.md
Last active May 10, 2020 07:59
Set up an ssh server with public key encryption. #ssh

Server

Create the user group and add the users you want to be part of this group:

sudo groupadd sshusers
sudo usermod -a -G sshusers <username>

Client

# Generate key and create password
@smac89
smac89 / Main.java
Last active May 10, 2020 05:53
Java sliding windows via Streams
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main {
public static void main(String args[]) {
Stream<List<Integer>> stream = SlidingWindow.pagedStream(StreamableSupplier.fromStream(IntStream.range(1, 10000).boxed()), 5)
.apply(i -> i <= 100);
stream.forEach(System.out::println);
@smac89
smac89 / Main.java
Last active January 24, 2023 21:32
Read a large json file, but do so lazily so as to not use too much memory. Thanks to Java 8 streams, this is quite possible
import com.google.common.io.Resources;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
@smac89
smac89 / nautilus-raw-preview.md
Last active May 10, 2020 08:11 — forked from h4cc/howto.md
Show previews of your image files in nautilus file manager in Ubuntu

Howto

Install these packages

sudo apt-get install gnome-raw-thumbnailer ufraw-batch

Check to see if everything works, and your thumbnails show up. If not, try the next part.

@smac89
smac89 / create_self_signed_pem_python.py
Last active September 26, 2017 15:43
Create a self-signed certificate for SSL encrypted http messaging
def _gen_private_pem_key():
from cryptography.hazmat.backends import default_backend as crypto_default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
key = rsa.generate_private_key(
backend=crypto_default_backend(),
public_exponent=65537,
key_size=2048
)
return key