Skip to content

Instantly share code, notes, and snippets.

View ShikiSuen's full-sized avatar
🍍

ShikiSuen ShikiSuen

🍍
View GitHub Profile
@rgo
rgo / gist:1324325
Created October 29, 2011 10:36
Convert files to utf-8 with vim
## From http://stackoverflow.com/questions/2311750/change-file-encoding-to-utf-8-via-vim-in-a-script
#This is the simplest way I know of to do this easily from the command line:
vim +"argdo se bomb | se fileencoding=utf-8 | w" $(find . -type f -name *.rb)
#Or better yet if the number of files is expected to be pretty large:
find . -type f -name *.rb | xargs vim +"argdo se bomb | se fileencoding=utf-8 | w"
@zhaoyk
zhaoyk / UIFont - CTFontRef 转换
Last active March 8, 2022 11:12
UIFont 与 CTFontRef 互相转换
+ (UIFont *)uifontFromCTFontRef:(CTFontRef)ctFont {
CGFloat pointSize = CTFontGetSize(ctFont);
NSString *fontPostScriptName = (NSString *)CFBridgingRelease(CTFontCopyPostScriptName(ctFont));
UIFont *fontFromCTFont = [UIFont fontWithName:fontPostScriptName size:pointSize];
return fontFromCTFont;
}
+ (CTFontRef)ctFontRefFromUIFont:(UIFont *)font {
CTFontRef ctfont = CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL);
return CFAutorelease(ctfont);
@kristopherjohnson
kristopherjohnson / FileHandleIterators.swift
Last active May 23, 2022 00:32
Iterators for reading bytes or lines from FileHandle objects as sequences
import Foundation
extension FileHandle {
/// Return an iterator over the bytes in the file.
///
/// - returns: An iterator for UInt8 elements.
public func bytes() -> FileHandleByteIterator {
return FileHandleByteIterator(fileHandle: self)
}
// USB Vendor ID: 0x05AC
// USB Product ID: 0x0251
/* The upper label indicates the key's function.
* The lower label indicates the USB/HID Keyboard report value.
* The keyboard report (endpoint 0x81) has the following data structure:
* ```
* struct kdb_report {
* uint8_t modifier;
* uint8_t reserved;
@jsoverson
jsoverson / device.css
Created February 15, 2013 20:06
Quick css hacks to target android/ios
.visible-android {
display:none;
}
.visible-ios {
display:none;
}
.on-device .visible-android, .on-device .visible-android {
display:inherit;
}
.device-ios .visible-android {
@eonist
eonist / TranslucentWin.swift
Created January 27, 2016 14:09
Translucent NSWindow Example
class TranslucentWin:NSWindow, NSApplicationDelegate, NSWindowDelegate{
/**
*
*/
override init(contentRect: NSRect, styleMask aStyle: Int, backing bufferingType: NSBackingStoreType, `defer` flag: Bool) {
super.init(contentRect: Win.sizeRect, styleMask: NSTitledWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask|NSFullSizeContentViewWindowMask, backing: NSBackingStoreType.Buffered, `defer`: false)
self.contentView!.wantsLayer = true;/*this can and is set in the view*/
self.backgroundColor = NSColor.greenColor().alpha(0.2)
self.opaque = false
self.makeKeyAndOrderFront(nil)//moves the window to the front
@KyLeggiero
KyLeggiero / NSWindow+Fade.swift
Last active September 23, 2022 16:00 — forked from indragiek/NSWindow+Fade.h
NSWindow+Fade - Animator proxy based NSWindow fading
//
// NSWindow+Fade.swift
// BH Bezel Notification
//
// Created by Ben Leggiero on 2017-11-09.
// Translated to Swift 4 from the original (ObjC): https://gist.github.com/indragiek/1397050
// Copyright © 2017 Ben Leggiero. All rights reserved.
//
import Foundation
@Jamesits
Jamesits / ubuntu_enable_bbr.sh
Last active December 13, 2022 22:27
Ubuntu enable BBR
#!/bin/bash
set -eu
SYSCTL_FILE=/etc/sysctl.d/90-tcp-bbr.conf
# check root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
@Victrid
Victrid / gitgraft.sh
Created August 29, 2022 17:09
Find which commit your no-git friend is working on and generate patches for attaching their works onto git tree.
#!/bin/bash
hash git 2>/dev/null || { echo >&2 "Required command 'git' is not installed. ( hmm... why are you using this? ) Aborting."; exit 1; }
hash realpath 2>/dev/null || { echo >&2 "Required command 'realpath' is not installed. Aborting."; exit 1; }
hash pwd 2>/dev/null || { echo >&2 "Required command 'pwd' is not installed. Aborting."; exit 1; }
hash cd 2>/dev/null || { echo >&2 "Required command 'cd' is not installed. Aborting."; exit 1; }
hash echo 2>/dev/null || { echo >&2 "Required command 'echo' is not installed. Aborting."; exit 1; }
hash mv 2>/dev/null || { echo >&2 "Required command 'mv' is not installed. Aborting."; exit 1; }
hash diff 2>/dev/null || { echo >&2 "Required command 'diff' is not installed. Aborting."; exit 1; }
hash diffstat 2>/dev/null || { echo >&2 "Required command 'diffstat' is not installed. Aborting."; exit 1; }
@gahntpo
gahntpo / SceneDelegate.swift
Created June 20, 2020 08:34
using the call to WindowScene( didUpdate) to access the window size and device orientation
func windowScene(_ windowScene: UIWindowScene,
didUpdate previousCoordinateSpace: UICoordinateSpace,
interfaceOrientation previousInterfaceOrientation: UIInterfaceOrientation,
traitCollection previousTraitCollection: UITraitCollection) {
// windowScene.coordinateSpace.bounds
// windowScene.interfaceOrientation.isLandscape
}