Skip to content

Instantly share code, notes, and snippets.

View smac89's full-sized avatar

Nobleman smac89

View GitHub Profile
@smac89
smac89 / gulp-typescript-compile-queue.ts
Last active July 6, 2017 21:13
Solution to "Error: gulp-typescript: A project cannot be used in two compilations * at the same time. Create multiple projects with createProject instead."
import {Project, CompileStream} from 'gulp-typescript';
import {Duplex, PassThrough, Readable} from 'stream';
import {Reporter} from 'gulp-typescript/release/reporter';
type Callback = () => void;
/**
* This is used to ensure that each project object is not busy when it is to be used
* This prevents the annoying:
* "Error: gulp-typescript: A project cannot be used in two compilations
@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
@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 / p4merge.sh
Created May 6, 2016 22:00
Script to install p4merge on Linux
#!/bin/bash
set -euf
if [[ ! "$#" = 1 ]]; then
echo "You need to supply the folder containing p4merge as arguement"
exit 1
elif [[ ! -d "$1" ]]; then
echo "The file is not a folder"
exit 1
@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 / 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 / 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 / fpr.py
Last active May 10, 2020 08:01
Floating point regex: A regular expression to match any valid python floating point value.
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
# See it in action https://regex101.com/r/ObowxD/5
import re
regex = r"""
(?xm)
(?:\s|^)
([-+]*(?:\d+\.\d*|\.?\d+)(?:[eE][-+]?\d+)?)
@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 / 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