Skip to content

Instantly share code, notes, and snippets.

@icasdri
icasdri / enc_wrapper.sh
Created July 2, 2016 19:41
Wrapper around ssh-keygen, openssl, and base64 to exchange small asymmetric encrypted messages
#!/bin/bash
# Copyright 2016 icasdri
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
/**
* Sets the POSIX group for a file, given the file's path as a string and the target group name.
*/
public static void reassignFileGroup(String filePath, String groupName) throws IOException {
Path path = Paths.get(filePath);
PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class);
UserPrincipalLookupService lookup = path.getFileSystem().getUserPrincipalLookupService();
GroupPrincipal group = lookup.lookupPrincipalByGroupName(groupName);
view.setGroup(group);
}
@icasdri
icasdri / CssTest.java
Created August 1, 2016 04:42
Java CSS Parser Test
import com.steadystate.css.parser.CSSOMParser;
import com.steadystate.css.parser.SACParserCSS3;
import org.w3c.css.sac.InputSource;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSRuleList;
import org.w3c.dom.css.CSSStyleSheet;
import java.io.IOException;
import java.io.StringReader;
# A simple systemd unit file for shadowsocks server (python version)
# See tutorial at shadowsocks' repo master: https://github.com/shadowsocks/shadowsocks/tree/master
#
# Prerequisites
# a) installed shadowsocks server in /usr/local/bin (the default if done through pip)
# b) shadowsocks server configuration json file in /etc/shadowsocks.json
# c) a user called "shadowsocks" that the server will run as
#
# Remember to place this file in /etc/systemd/systemd and then enable this unit with "systemctl enable shadowsocks.service" to have it start at boot
@icasdri
icasdri / GeneralAverage.java
Last active September 28, 2016 02:55
Java one-liner for taking mean of two ints without overflow
import java.util.Random;
public class GeneralAverage {
public static int mean(int a, int b) {
return ((a<0) ^ (b<0)) ? (a + b) / 2 : (a%2 == 0 || b%2 == 0 ? a/2 + b/2 : a/2 + b/2 + ((a < 0) ? -1 : 1));
}
public static void main(String[] args) {
Random rand = new Random();
int a = Integer.MAX_VALUE;
@icasdri
icasdri / ajax.js
Last active January 14, 2017 21:23
Simple, easy-to-use, super-light, ajax() function wrapping XMLHttpRequest
/*
Performs an AJAX (XMLHttpRequest) request where
- method is the HTTP verb to use (e.g. 'POST')
- dest is the destination endpoint path (e.g. '/api/endpoint')
- type concerns how the response should be handled (e.g. 'json')
- success is callback function that takes a response body
- error is a callback funtion that takes a full error response object
- data is data to send to the server (as in 'POST')
*/
@icasdri
icasdri / Hello.java
Last active November 5, 2017 00:48
Write Java with only a C compiler
public class Hello {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
@icasdri
icasdri / Makefile
Created August 16, 2018 18:08 — forked from ddevault/Makefile
Tiny Wayland compositor
WAYLAND_PROTOCOLS=/usr/share/wayland-protocols
# wayland-scanner is a tool which generates C headers and rigging for Wayland
# protocols, which are specified in XML. wlroots requires you to rig these up
# to your build system yourself and provide them in the include path.
xdg-shell-protocol.h:
wayland-scanner server-header \
$(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
xdg-shell-protocol.c: xdg-shell-protocol.h
@icasdri
icasdri / tiny_IRremote.cpp
Created September 2, 2021 22:13 — forked from SeeJayDee/tiny_IRremote.cpp
tiny_IRremote - Arduino IRremote ported to the ATtiny
/*
* tiny_IRremote
* Version 0.2 July, 2016
* Christian D'Abrera
* Fixed what was originally rather broken code from http://www.gammon.com.au/Arduino/
* ...itself based on work by Ken Shirriff.
*
* This code was tested for both sending and receiving IR on an ATtiny85 DIP-8 chip.
* IMPORTANT: IRsend only works from PB4 ("pin 4" according to Arduino). You will need to
* determine which physical pin this corresponds to for your chip, and connect your transmitter
#!/bin/bash
# note: current working directory ($PWD) assumed to be directory containing a static podman installation
# replace all occurrences of /path/to/static/podman with actual value of $PWD
cp storage.conf "$HOME/.config/containers/storage.conf"
PATH="$PWD/usr/local/bin:$PATH" ./usr/local/bin/podman \
--conmon "$PWD/usr/local/lib/podman/conmon" \
--runtime runc \