Skip to content

Instantly share code, notes, and snippets.

@nemesit
nemesit / postfix and prefix increment decrement.swift
Last active December 14, 2015 12:50
postfix increment/decrement and prefix increment/decrement, for those who will miss them in Swift 3
postfix operator +++ {}
postfix func +++(inout left: Int) -> Int {
defer {left += 1}
return left
}
postfix operator --- {}
postfix func ---(inout left: Int) -> Int {
defer {left -= 1}
return left
}
extension Character: ForwardIndexType {
public func successor() -> Character {
return Character(UnicodeScalar(String(self).unicodeScalars.first!.value + 1))
}
}
%!TEX TS-program = lualatex
%!TEX TS-options = --shell-escape
\documentclass{scrreprt}
\usepackage[autostyle]{csquotes}
\usepackage[urw-garamond]{mathdesign}
%\usepackage[euler-digits,euler-hat-accent]{eulervm} % math TODO: not working load before fontspec
\usepackage[no-math]{fontspec}
@nemesit
nemesit / writeToFile
Created June 30, 2014 20:12
Swift write to file
import Foundation
let dir = "~/Desktop"
let file = "test.txt"
let path = dir.stringByExpandingTildeInPath
let filePath:NSString = path.stringByAppendingPathComponent(file)
var text: NSString = "random text with no meaning"
var textData: NSData = text.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
var f: CMutablePointer = fopen(filePath.UTF8String, "w".UTF8String)
@nemesit
nemesit / IMPSEL
Created June 24, 2014 18:01
calling the method implementation as an alternative to performSelector
if ([_target respondsToSelector:_targetAction]) {
if (_targetAction) {
void (*action)(id,SEL,id);
action = (void(*)(id,SEL,id))[_target methodForSelector:_targetAction];
action(_target,_targetAction,self);
}
}
# uninstall google updater
~/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/GoogleSoftwareUpdateAgent.app/Contents/Resources/install.py --uninstall
# prevent reinstall
touch ~/Library/Google/GoogleSoftwareUpdate
sudo chown root ~/Library/Google/GoogleSoftwareUpdate
sudo chmod 644 ~/Library/Google/GoogleSoftwareUpdate
@nemesit
nemesit / test.rb
Last active December 16, 2015 05:19
ruby Discover if a number is prime http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/ Source Article
class Fixnum
def prime?
('1' * self) !~ /^1?$|^(11+?)\1+$/
end
end
Wohoo a test paste
with test text
and test linebreaks