Skip to content

Instantly share code, notes, and snippets.

@sooop
sooop / property-sample.swift
Created January 22, 2018 04:09
Swift 클래스의 프로퍼티와 상속 예제
//: Playground - noun: a place where people can play
//: ## 1 : 클래스의 프로퍼티 정의방법
class Foo {
/// 일반적인 stored property
var a: Int = 4
/// stored property + observer methods
var b: Int = 10 {
willSet {
@sooop
sooop / to_many_kvo.swift
Last active January 10, 2018 03:30
to-many relationship에 대한 KVO 처리방법
import Foundation
// MARK: Employee
class Employee: NSObject
{
@objc dynamic var salary:Int
var name: String
init(name:String, salary:Int) {
self.name = name
@sooop
sooop / main.m
Created January 9, 2018 23:48
Basic KVC/KVO Implementation
#import <Foundation/Foundation.h>
static void* theContext = &theContext;
/// KVC/KVO 호환 클래스.
@interface Foo: NSObject
@property (copy, nonatomic) NSString* moo;
-(void)doubleBar;
@end
@sooop
sooop / get_tumblr.py
Created December 2, 2017 15:28
텀블러 비디오 자동 다운로드 데몬
from urllib.request import urlopen
from subprocess import check_call
from queue import Queue
from threading import Thread, Lock
from tkinter import Tk
import re
import time
app = Tk()
app.withdraw()
@sooop
sooop / client.py
Created November 24, 2017 09:37
파일 개수를 체크하여 클라이언트에게 알려주는 소켓서버 구현
import socket
def client():
host, port = '127.0.0.1', 4000
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
print(s.recv(4096).decode())
print(s.recv(4096).decode())
pen n = (flip div 2) $ n * (n * 3 - 1)
main = getLine >> getContents >>= putStrLn . unlines . map (show . pen .read) . lines
@sooop
sooop / h011.hs
Created September 18, 2017 09:30
-- 구분구적법으로 곡선아래의 넓이와 회전체의 부피를 구하라.
{- 입력은 세 라인으로
- 첫 줄은 다항식의 각 계수
- 둘째줄은 다항식의 각 차수
- 셋째줄은 구간의 시작값과 끝값
-
-
- 구분 구적법에서 다항식 곡선의 넓이는 다음과 같이 계산한다.
- 시작값과 끝값사이에서 gap 만큼 조금씩 움직인다.
- x0 = leftBound + (gap_count * gap_size)
@sooop
sooop / paste.ls
Created September 17, 2017 00:51
# handle paste event
# paste image file to body
add-image = (img-file) !->
an-image = document.create-element \img
reader = new FileReader!
# handle paste event
# paste image file to body
add-image = (img-file) !->
# img-file :: File
# -- FileReader를 써서 읽어들여서 사용한다.
#!/usr/bin/swift
import Foundation
let masks: [String] = ["02356789", "045689", "01234789",
"2345689", "0268", "013456789", "0235689"]
let digits = "1234567890"
let s = 3
@sooop
sooop / print_digits.py
Last active September 6, 2017 23:33
display LCD Digits
def present(s, digits):
masks = ('02356789', '045689', '01234789', '2345689', '0268', '013456789', '0235689')
result = []
h = lambda x: ' '.join(' ' + ('-' if d in masks[x] else ' ') * s + ' '\
for d in digits)
v = lambda x: ' '.join(('|' if d in masks[x] else ' ') + ' ' * s +\
('|' if d in masks[x+1] else ' ') for d in digits)
result.append(h(0))
result += [v(1)] * s
result.append(h(3))