Skip to content

Instantly share code, notes, and snippets.

nyg

Block or report user

Report or block nyg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am nyg on github.
  • I am ngaranis (https://keybase.io/ngaranis) on keybase.
  • I have a public key ASB-F2fnOPuIOpWWLKsB-b8ZJ0MNhPoXSvSdblQLuYfBzQo

To claim this, I am signing this object:

@nyg
nyg / auto_extract.sh
Created Apr 2, 2019
Script to recursively extract archives
View auto_extract.sh
#!/usr/bin/env bash
# Usage: /absolute/path/to/script.sh /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:]')
@nyg
nyg / get-el-capitan.sh
Created Mar 16, 2019
Download El Capitan from Apple's servers.
View get-el-capitan.sh
#!/usr/bin/env sh
#
# Requires wget.
# Does not work on Mojave because of the new App Store.
#
# Inspiration source:
# https://7labs.io/tips-tricks/el-capitan-direct-download.html (and comments)
#
# See also:
# https://apple.stackexchange.com/questions/309399/how-can-i-download-an-older-version-of-os-x-macos
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
nyg / EXIFUserComment.swift
Last active Apr 21, 2019
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:
// https://gist.github.com/nyg/bdeae8190a41b4b56bde8e13dd471ecc
import Foundation
import ImageIO
#if os(iOS)
import MobileCoreServices
#endif
@nyg
nyg / AsynchronousServerSocketChannelTest.java
Created Sep 15, 2017
Basic code example for AsynchronousServerSocketChannel.
View AsynchronousServerSocketChannelTest.java
AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(ip, port));
while (true) {
Future<AsynchronousSocketChannel> future = listener.accept();
AsynchronousSocketChannel channel = future.get();
ByteBuffer buffer = ByteBuffer.allocate(5000);
Future<Integer> byteCount = channel.read(buffer);
System.out.println("Bytes read: " + byteCount.get());
@nyg
nyg / AddJPEGComment.swift
Last active Sep 20, 2017
Add a JPEG comment marker to file in pure Swift.
View AddJPEGComment.swift
//
// Inspired by wrjpgcom of libjpeg
// https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/wrjpgcom.c
//
// https://stackoverflow.com/a/46045524/5536516
//
// Note: To add an EXIF UserComment go here:
// https://gist.github.com/nyg/c90f36abbd30f72c8b6681ef23db886b
import Foundation
@nyg
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) {
self.name = name
self.age = age
@nyg
nyg / MemoryAddress.swift
Last active Nov 21, 2019
Get the memory address of both class and structure instances in Swift.
View MemoryAddress.swift
// https://stackoverflow.com/a/45777692/5536516
import Foundation
struct MemoryAddress<T>: CustomStringConvertible {
let intValue: Int
var description: String {
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size
@nyg
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.