This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.lang.reflect.Field; | |
import java.nio.charset.StandardCharsets; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.StandardOpenOption; | |
import java.security.Provider; | |
import java.security.Security; | |
import java.util.Arrays; | |
import java.util.Collection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer | |
// Note: including images in the HTML won't work, see here: | |
// https://github.com/nyg/HTMLWithImagesToPDF | |
import UIKit | |
// 1. Create a print formatter | |
let html = "<b>Hello <i>World!</i></b>" | |
let fmt = UIMarkupTextPrintFormatter(markupText: html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/45068046/5536516 | |
import Foundation | |
func kernelBootTime() -> timeval { | |
var mib = [ CTL_KERN, KERN_BOOTTIME ] | |
var bootTime = timeval() | |
var bootTimeSize = MemoryLayout<timeval>.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$filename = $argv[1]; | |
$growthFactor = $argv[2]; | |
list($width_orig, $height_orig) = getimagesize($filename); | |
$width = $width_orig * $growthFactor; | |
$height = $height_orig * $growthFactor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.self.nyg.example.jmx.app; | |
import java.lang.management.ManagementFactory; | |
import java.text.NumberFormat; | |
import java.util.Set; | |
import javax.management.MBeanServer; | |
import javax.management.ObjectInstance; | |
import lombok.extern.slf4j.Slf4j; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on https://usehooks.com/useLocalStorage/, modified to be used with | |
// Next.js' server-side rendering components. | |
import { useState } from "react"; | |
export default function useLocalStorage(key, initialValue) { | |
// There is no need to pass the inital value here as this will be executed on | |
// the server side, so window.localStorage is not available. | |
const [stateValue, setStateValue] = useState() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'http' | |
const options = { | |
hostname: 'perdu.com', | |
method: 'GET', | |
} | |
const req = http.request(options, res => { | |
console.log(`Status: ${res.statusCode}`) |
NewerOlder