Skip to content

Instantly share code, notes, and snippets.


Nicolas Garanis nyg

View GitHub Profile
nyg / pdk.c
Created Apr 21, 2020
Create a password-derived key using libsodium.
View pdk.c
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the

Keybase proof

I hereby claim:

  • I am nyg on github.
  • I am ngaranis ( on keybase.
  • I have a public key ASB-F2fnOPuIOpWWLKsB-b8ZJ0MNhPoXSvSdblQLuYfBzQo

To claim this, I am signing this object:

nyg /
Created Apr 2, 2019
Script to recursively extract archives
#!/usr/bin/env bash
# Usage: /absolute/path/to/ /absolute/path/to/folder/with/archive
for file in $1/* ; do
if [ -f "$file" ] ; then
echo Found file: $file
info=$(file $file | tr '[:upper:]' '[:lower:]')
View div_euc_hex.c
#include <stdio.h>
int main(int argc, const char** argv) {
unsigned int a = 0xDEADBEEF;
unsigned int b = 0xBABE;
unsigned int q = a / b;
unsigned int r = a % b;
printf("%u = %u * %u + %u\n", a, q, b, r);
nyg / EXIFUserComment.swift
Last active Aug 30, 2020
Get and set an EXIF UserComment to a JPEG image using the ImageIO framework.
View EXIFUserComment.swift
// Note: to add a JPEG COM marker go here:
import Foundation
import ImageIO
#if os(iOS)
import MobileCoreServices
nyg /
Created Sep 15, 2017
Basic code example for AsynchronousServerSocketChannel.
AsynchronousServerSocketChannel listener = InetSocketAddress(ip, port));
while (true) {
Future<AsynchronousSocketChannel> future = listener.accept();
AsynchronousSocketChannel channel = future.get();
ByteBuffer buffer = ByteBuffer.allocate(5000);
Future<Integer> byteCount =;
System.out.println("Bytes read: " + byteCount.get());
nyg / AddJPEGComment.swift
Last active Aug 13, 2020
Add a JPEG comment marker to file in pure Swift.
View AddJPEGComment.swift
// Inspired by wrjpgcom of libjpeg
// Note: To add an EXIF UserComment go here:
import Foundation
nyg / Serialize.swift
Created Aug 29, 2017
Serialize NSObject (or array of) to XML in Swift.
View Serialize.swift
import Foundation
class MyClass: NSObject, NSCoding {
var name: String
var age: Int
init(name: String, age: Int) { = name
self.age = age
nyg / MemoryAddress.swift
Last active Sep 12, 2020
Get the memory address of both class and structure instances in Swift.
View MemoryAddress.swift
import Foundation
struct MemoryAddress<T>: CustomStringConvertible {
let intValue: Int
var description: String {
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size
nyg / uptime.c
Last active Aug 14, 2017
Get boot time and uptime on macOS in C
View uptime.c
// Tested on macOS 10.12.
// Usage:
// $ clang uptime.c && ./a.out
// boot time (UNIX time): 1502299682.147510
// uptime (seconds): 410563.269028116
#include <stdlib.h>
#include <errno.h>
#include <string.h>
You can’t perform that action at this time.