Skip to content

Instantly share code, notes, and snippets.

@nyg
nyg / kraken-ledger.js
Created May 30, 2014 21:32
Get all entries of your Kraken.com ledger.
/* Querying your ledger through Kraken's API only return 50 results... */
var KrakenClient = require('kraken-api'); // https://github.com/nothingisdead/npm-kraken-api
var kraken = new KrakenClient('api_key', 'api_secret');
var ledger = [];
var offset = 0;
function getLedgerEntries (error, data) {
@nyg
nyg / iOSCreatePDF.swift
Last active April 2, 2024 11:09
iOS, Swift: Create a PDF file from an HTML string.
// 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)
@nyg
nyg / fk_delete_recursive.sql
Last active August 25, 2017 08:01
Oracle: delete a row and all rows preventing it to be deleted because of "child record found" errors.
DECLARE
-- ORA-02292: integrity constraint (OWNER.FK) violated - child record found
ora_02292 EXCEPTION;
PRAGMA EXCEPTION_INIT(ora_02292, -2292);
l_foreign_key VARCHAR2(400);
PROCEDURE delete_row(pi_table IN VARCHAR2,
pi_column IN VARCHAR2,
pi_value IN VARCHAR2) IS
@nyg
nyg / fk_generate_delete.sql
Created January 11, 2017 10:03
Oracle: outputs the necessary delete statements to delete a row and all rows preventing it from being deleted because of "child record found" error.
DECLARE
g_level INTEGER := 0;
g_owner VARCHAR2(10) := 'owner';
PROCEDURE find_fk(pi_table IN VARCHAR2,
pi_where IN VARCHAR2) IS
l_where VARCHAR2(500);
l_pad VARCHAR2(100);
BEGIN
g_level := g_level + 1;
@nyg
nyg / enlarge_image.php
Last active February 27, 2024 22:15
Enlarge a given image.
<?php
$filename = $argv[1];
$growthFactor = $argv[2];
list($width_orig, $height_orig) = getimagesize($filename);
$width = $width_orig * $growthFactor;
$height = $height_orig * $growthFactor;
@nyg
nyg / sequence_iterator.swift
Last active September 20, 2017 11:41
Implementing Sequence & IteratorProtocol, Swift 3
import Foundation
class Cell {
var name: String
init(_ name: String) {
self.name = name
}
}
@nyg
nyg / UIApplicationDelegate.swift
Created July 10, 2017 14:30
Adding `shared` property to UIApplicationDelegate
// https://stackoverflow.com/a/45014628/5536516
extension UIApplicationDelegate {
static var shared: Self {
return UIApplication.shared.delegate! as! Self
}
}
/*
@nyg
nyg / Uptime.swift
Last active April 1, 2024 21:35
Get boot time and uptime for macOS & iOS.
// 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
@nyg
nyg / yql_json.html
Created August 6, 2017 13:27
Using Yahoo Query Language (YQL) to get JSON from an external URL and bypass the Access-Control-Allow-Origin restriction.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Using YQL to get JSON from an external URL</title>
<meta charset="utf-8" />
</head>
<body>
<pre id='json'></pre>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script>
@nyg
nyg / uptime.c
Last active April 1, 2024 21:33
Get boot time and uptime on macOS in 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>