Skip to content

Instantly share code, notes, and snippets.

@wannyk
wannyk / urlencode.js
Created December 4, 2020 16:33
encode utf8 string to euc-kr
const iconv = require('iconv-lite');
const assert = require('assert');
const urlencode = input => input.replace(/[^A-Za-z0-9-_.!~*'()]/g, c => c==' ' ? '+' : [...iconv.encode(c, "EUC-KR")].map(b => '%'+b.toString(16).toUpperCase()).join(''));
assert(urlencode('2013_16_방파제축조공사 추가절차 공사비 청구.pdf')=='2013_16_%B9%E6%C6%C4%C1%A6%C3%E0%C1%B6%B0%F8%BB%E7+%C3%DF%B0%A1%C0%FD%C2%F7+%B0%F8%BB%E7%BA%F1+%C3%BB%B1%B8.pdf')
@wannyk
wannyk / _service.md
Last active August 17, 2016 08:58 — forked from naholyr/_service.md
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@wannyk
wannyk / gevent-multiprocess.py
Created November 6, 2015 06:43 — forked from denik/gevent-multiprocess.py
gevent-multiprocess
import sys
from gevent import server
from gevent.server import _tcp_listener
from gevent.monkey import patch_all; patch_all()
from multiprocessing import Process, current_process, cpu_count
def note(format, *args):
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
@wannyk
wannyk / SVD.swift
Created October 30, 2015 08:04
MATLAB svd(x) in Swift
//
// SVD.swift
//
// Created by Dongwan Kim on 2015. 10. 30..
//
/* MATLAB svd(X)
For the matrix
@wannyk
wannyk / CGSizeAspect.m
Created July 31, 2015 07:51
CGSizeAspectFit & CGSizeAspectFill from http://stackoverflow.com/a/17948778
CGSize CGSizeAspectFit(CGSize aspectRatio, CGSize boundingSize)
{
float mW = boundingSize.width / aspectRatio.width;
float mH = boundingSize.height / aspectRatio.height;
if( mH < mW )
boundingSize.width = boundingSize.height / aspectRatio.height * aspectRatio.width;
else if( mW < mH )
boundingSize.height = boundingSize.width / aspectRatio.width * aspectRatio.height;
return boundingSize;
}
@wannyk
wannyk / StatusBarAndNavBarHeight.m
Created July 31, 2015 05:20
StatusBarAndNavBarHeight
CGFloat StatusBarAndNavBarHeight(UINavigationController *navController)
{
CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
return navController.navigationBar.frame.size.height+MIN(statusBarSize.width, statusBarSize.height);
}
@wannyk
wannyk / CFNetworkErrors.h
Created December 22, 2014 04:20
From iOS 8.1
/*
File: CFNetwork/CFNetworkErrors.h
Contains: CFNetwork error header
Copyright: Copyright (c) 2006-2013 Apple Inc. All rights reserved.
Bugs?: For bug reports, consult the following page on
the World Wide Web:
#!/bin/bash
for f in $(ls *@2x.png)
do
filename=$(basename $f | sed 's/@2x././g')
echo $filename
H=$(sips -g pixelHeight "$f" | grep 'pixelHeight' | cut -d: -f2)
W=$(sips -g pixelWidth "$f" | grep 'pixelWidth' | cut -d: -f2)
H50=$(($H / 2))