Skip to content

Instantly share code, notes, and snippets.

View kimjj81's full-sized avatar

Jeongjin Kim kimjj81

View GitHub Profile
@kimjj81
kimjj81 / UInt_extension.swift
Last active February 23, 2024 06:53
Convert UInt to UInt8(byte) Array in swift.
protocol UIntToBytesConvertable {
var toBytes: [UInt8] { get }
}
extension UIntToBytesConvertable {
func toByteArr<T: BinaryInteger>(endian: T, count: Int) -> [UInt8] {
var _endian = endian
let bytePtr = withUnsafePointer(to: &_endian) {
$0.withMemoryRebound(to: UInt8.self, capacity: count) {
UnsafeBufferPointer(start: $0, count: count)
@kimjj81
kimjj81 / SimplePaginator
Created December 6, 2019 09:36
Paginator for numerous records in Django-admin.
from django.core.paginator import Paginator
class SimpleCountPaginator(Paginator):
def _get_count(self):
try:
first_id = self.object_list.first().id
last_id = self.object_list.last().id
if (first_id is None) or (last_id is None):
return 0
max_id = max(last_id, first_id)
@kimjj81
kimjj81 / install-ubuntu-server-via-console.md
Created November 6, 2019 08:57 — forked from maixuanhan/install-ubuntu-server-via-console.md
Install Ubuntu server 18.04 via USB disk and serial console
@kimjj81
kimjj81 / PBKDF2withHmacSHA1.java
Created April 30, 2018 09:04
PBKDF2withHmacSHA1
public static String makePasswordHash(String text) {
byte[] salt = "yoursalt".getBytes(Charsets.UTF_8);
try {
char[] chars = text.toCharArray();
final int iterations = 10;
// Generate a 256-bit key
final int outputKeyLength = 256;
@kimjj81
kimjj81 / PBKDF2.m
Created April 30, 2018 09:00
PBKDF2 Objective-c
#import <CommonCrypto/CommonCrypto.h>
+ (NSString*)onewayHash:(NSString *)text {
NSMutableData *key = [NSMutableData dataWithLength:kCCKeySizeAES256];
NSString *password = text;
NSString* saltText = @"salt";
NSData* salt = [saltText dataUsingEncoding:NSUTF8StringEncoding];
int result = CCKeyDerivationPBKDF(kCCPBKDF2, // algorithm
@kimjj81
kimjj81 / PasswordUtils.java
Created April 30, 2018 07:16 — forked from ToastShaman/PasswordUtils.java
A utility class for hashing passwords using PBKDF2 with BouncyCastle.
package com.zuhlke.lsapi;
import org.bouncycastle.crypto.PBEParametersGenerator;
import org.bouncycastle.crypto.digests.SHA3Digest;
import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.prng.DigestRandomGenerator;
import java.util.Base64;
@kimjj81
kimjj81 / Save CGImage
Last active September 19, 2017 07:09
resize uiimage
void CGImageWriteToFile(CGImageRef image, NSString *path) {
CFURLRef url = (__bridge CFURLRef) [NSURL fileURLWithPath:path];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(destination, image, nil);
if (!CGImageDestinationFinalize(destination)) {
NSLog(@"Failed to write image to %@", path);
}
}