Redis Tutorial

Redis Tutorial

http://try.redis.io

Key-Value

SET

SET server:name "fido"

GET

GET server:name

INCR

SET connections 10
INCR connections

DEL

DEL connections

EXPR

SET resource:lock "Redis Demo 1"
EXPIRE resource:lock 120
TTL resource:lock

List

RPUSH

RPUSH friends "Alice"
RPUSH friends "Bob"

LPUSH

LPUSH friends "Sam"

LRANGE

LRANGE friends 0 -1
LRANGE friends 1 2

A value of -1 for the second parameter means to retrieve elements until the end of the list.

LLEN

LLEN friends

LPOP

LPOP friends

RPOP

RPOP friends

Set

SADD

SADD superpowers "flight"

SREM

SREM superpowers "reflexes"

SISMEMBER

SISMEMBER tests if the given value is in the set.

SISMEMBER superpowers "flight"

SMEMBERS

SMEMBERS returns a list of all the members of this set.

SMEMBERS superpowers

SUNION

SUNION combines two or more sets and returns the list of all elements.

Sorted Set

ZADD

ZADD hackers 1940 "Alan Kay"
ZADD hackers 1906 "Grace Hopper"
ZADD hackers 1953 "Richard Stallman"
ZADD hackers 1965 "Yukihiro Matsumoto"
ZADD hackers 1916 "Claude Shannon"
ZADD hackers 1969 "Linus Torvalds"
ZADD hackers 1957 "Sophie Wilson"
ZADD hackers 1912 "Alan Turing"

ZRANGE

ZRANGE hackers 2 4

Hash

HSET

HSET user:1000 name "John Smith"
HSET user:1000 email "john.smith@example.com"
HSET user:1000 password "s3cret"

HGET

HGET user:1001 name

HGETALL

HGETALL user:1000

HMSET

HMSET user:1001 name "Mary Jones" password "hidden" email "mjones@example.com"

안드로이드 배터리 잔량 구하기

Intent.ACTION_BATTERY_CHANGED는 Sticky Intent로 시스템에 등록되어 있어서 registerReceiver()를 호출하면 즉시 반환됩니다. 반환된 Intent에서 필요한 값을 추출해 배터리 잔량을 %로 계산해 반환하는 메서드입니다.

public static int getBatteryPercentage(Context context) {
    Intent batteryStatus = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

    float batteryPct = level / (float)scale;
    return (int)(batteryPct * 100);
}

Sublime Text 3에서 Markdown Syntax Highlighting 적용하기

Sublime Text 3로 Markdown 문서를 편집하고 Marked 2로 Preview를 확인하면서 글을 작성하는 연습을 하고 있습니다.

Sublime Text 3의 아쉬운 점은 Markdown Syntax Highlighting을 지원하지 않더군요. 구글 검색을 통해 관련 문서를 찾았는데, 기본적으로는 버전 2에서 적용방법을 설명하고 있지만, 댓글에 버전 3을 위한 적용방법도 나와 있어 여기에 정리하여 공유합니다.

~/Library/Application Support/Sublime Text 3/Packages/User/customizedMonokai.tmTheme 파일에 다음 내용을 붙여 넣습니다. (기본 테마의 끝부분에 Markdown을 위한 테마를 추가한 것입니다.)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Monokai</string>
    <key>settings</key>
    <array>
        <dict>
            <key>settings</key>
            <dict>
                <key>background</key>
                <string>#272822</string>
                <key>caret</key>
                <string>#F8F8F0</string>
                <key>foreground</key>
                <string>#F8F8F2</string>
                <key>invisibles</key>
                <string>#3B3A32</string>
                <key>lineHighlight</key>
                <string>#3E3D32</string>
                <key>selection</key>
                <string>#49483E</string>
                <key>findHighlight</key>
                <string>#FFE792</string>
                <key>findHighlightForeground</key>
                <string>#000000</string>
                <key>selectionBorder</key>
                <string>#222218</string>
                <key>activeGuide</key>
                <string>#9D550FB0</string>

                <key>bracketsForeground</key>
                <string>#F8F8F2A5</string>
                <key>bracketsOptions</key>
                <string>underline</string>

                <key>bracketContentsForeground</key>
                <string>#F8F8F2A5</string>
                <key>bracketContentsOptions</key>
                <string>underline</string>

                <key>tagsOptions</key>
                <string>stippled_underline</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Comment</string>
            <key>scope</key>
            <string>comment</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#75715E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>String</string>
            <key>scope</key>
            <string>string</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#E6DB74</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Number</string>
            <key>scope</key>
            <string>constant.numeric</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#AE81FF</string>
            </dict>
        </dict>

        <dict>
            <key>name</key>
            <string>Built-in constant</string>
            <key>scope</key>
            <string>constant.language</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#AE81FF</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>User-defined constant</string>
            <key>scope</key>
            <string>constant.character, constant.other</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#AE81FF</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Variable</string>
            <key>scope</key>
            <string>variable</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Keyword</string>
            <key>scope</key>
            <string>keyword</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#F92672</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Storage</string>
            <key>scope</key>
            <string>storage</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#F92672</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Storage type</string>
            <key>scope</key>
            <string>storage.type</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>italic</string>
                <key>foreground</key>
                <string>#66D9EF</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Class name</string>
            <key>scope</key>
            <string>entity.name.class</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>underline</string>
                <key>foreground</key>
                <string>#A6E22E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Inherited class</string>
            <key>scope</key>
            <string>entity.other.inherited-class</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>italic underline</string>
                <key>foreground</key>
                <string>#A6E22E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Function name</string>
            <key>scope</key>
            <string>entity.name.function</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#A6E22E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Function argument</string>
            <key>scope</key>
            <string>variable.parameter</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>italic</string>
                <key>foreground</key>
                <string>#FD971F</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Tag name</string>
            <key>scope</key>
            <string>entity.name.tag</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#F92672</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Tag attribute</string>
            <key>scope</key>
            <string>entity.other.attribute-name</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#A6E22E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Library function</string>
            <key>scope</key>
            <string>support.function</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#66D9EF</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Library constant</string>
            <key>scope</key>
            <string>support.constant</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#66D9EF</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Library class/type</string>
            <key>scope</key>
            <string>support.type, support.class</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>italic</string>
                <key>foreground</key>
                <string>#66D9EF</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Library variable</string>
            <key>scope</key>
            <string>support.other.variable</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Invalid</string>
            <key>scope</key>
            <string>invalid</string>
            <key>settings</key>
            <dict>
                <key>background</key>
                <string>#F92672</string>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#F8F8F0</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>Invalid deprecated</string>
            <key>scope</key>
            <string>invalid.deprecated</string>
            <key>settings</key>
            <dict>
                <key>background</key>
                <string>#AE81FF</string>
                <key>foreground</key>
                <string>#F8F8F0</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>JSON String</string>
            <key>scope</key>
            <string>meta.structure.dictionary.json string.quoted.double.json</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#CFCFC2</string>
            </dict>
        </dict>

        <dict>
            <key>name</key>
            <string>diff.header</string>
            <key>scope</key>
            <string>meta.diff, meta.diff.header</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#75715E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>diff.deleted</string>
            <key>scope</key>
            <string>markup.deleted</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#F92672</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>diff.inserted</string>
            <key>scope</key>
            <string>markup.inserted</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#A6E22E</string>
            </dict>
        </dict>
        <dict>
            <key>name</key>
            <string>diff.changed</string>
            <key>scope</key>
            <string>markup.changed</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#E6DB74</string>
            </dict>
        </dict>

        <dict>
            <key>scope</key>
            <string>constant.numeric.line-number.find-in-files - match</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#AE81FFA0</string>
            </dict>
        </dict>
        <dict>
            <key>scope</key>
            <string>entity.name.filename</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#E6DB74</string>
            </dict>
        </dict>

        <dict>
            <key>scope</key>
            <string>message.error</string>
            <key>settings</key>
            <dict>
                <key>foreground</key>
                <string>#F83333</string>
            </dict>
        </dict>

<dict>
  <key>name</key>
  <string>Markdown: Linebreak</string>
  <key>scope</key>
  <string>text.html.markdown meta.dummy.line-break</string>
  <key>settings</key>
  <dict>
    <key>background</key>
    <string>#A57706</string>
    <key>foreground</key>
    <string>#E0EDDD</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markdown: Raw</string>
  <key>scope</key>
  <string>text.html.markdown markup.raw.inline</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#269186</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markdown: Punctuation for Inline Block</string>
  <key>scope</key>
  <string>punctuation.definition.raw.markdown</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#269186</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markup: Heading</string>
  <key>scope</key>
  <string>markup.heading</string>
  <key>settings</key>
  <dict>
    <key>fontStyle</key>
    <string>bold</string>
    <key>foreground</key>
    <string>#cb4b16</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markup: Italic</string>
  <key>scope</key>
  <string>markup.italic</string>
  <key>settings</key>
  <dict>
    <key>fontStyle</key>
    <string>italic</string>
    <key>foreground</key>
    <string>#839496</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markup: Bold</string>
  <key>scope</key>
  <string>markup.bold</string>
  <key>settings</key>
  <dict>
    <key>fontStyle</key>
    <string>bold</string>
    <key>foreground</key>
    <string>#586e75</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markdown: Punctuation for Bold, Italic</string>
  <key>scope</key>
  <string>punctuation.definition.bold.markdown, punctuation.definition.italic.markdown</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#586e75</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markup: Underline</string>
  <key>scope</key>
  <string>markup.underline</string>
  <key>settings</key>
  <dict>
    <key>fontStyle</key>
    <string>underline</string>
    <key>foreground</key>
    <string>#839496</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markup: Quote</string>
  <key>scope</key>
  <string>markup.quote</string>
  <key>settings</key>
  <dict>
    <key>fontStyle</key>
    <string>italic</string>
    <key>foreground</key>
    <string>#268bd2</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>Markup: Separator</string>
  <key>scope</key>
  <string>meta.separator</string>
  <key>settings</key>
  <dict>
    <key>background</key>
    <string>#eee8d5</string>
    <key>fontStyle</key>
    <string>bold</string>
    <key>foreground</key>
    <string>#268bd2</string>
  </dict>
</dict>

    </array>
    <key>uuid</key>
    <string>D8D5E82E-3D5B-46B5-B38E-8C841C21347D</string>
</dict>
</plist>

Sublime Text 3에서 Preferences > Settings - User 메뉴를 실행하면 Preferences.sublime-settings 파일이 열립니다. 아래와 같이 수정해 줍니다.

// Settings in here override those in "Default/Preferences.sublime-settings",
// and are overridden in turn by file type specific settings.
{
    "color_scheme": "Packages/User/customizedMonokai.tmTheme"
}

결과는 이렇습니다.

스크린샷 2013-10-31 오후 10.57.36

Xcode 5에서 Storyboard 사용하지 않는 Single View Application 프로젝트 생성하기

Xcode 4에서는 프로젝트를 생성할때 Storyboard 사용여부를 선택할 수 있는 옵션이 제공되었지만, Xcode 5에서는 이 옵션이 삭제되었습니다. 대안으로 아래와 같은 방법으로 Xcode 4에서와 마찬가지로 XIB를 사용하는 Single View Application 프로젝트를 생성할 수 있습니다.

스크린샷 2013-10-16 오후 11.48.44

Single View Application 대신에 Empty Application을 선택하여 프로젝트를 생성합니다.

스크린샷 2013-10-16 오후 11.53.40

프로젝트는 초기화 되었지만 UI 관련 파일은 보이지 않습니다.

스크린샷 2013-10-16 오후 11.55.19

New File에서 iOS > Cocoa Touch > Object-C class를 선택해

스크린샷 2013-10-16 오후 11.57.20

UIViewController를 상속하는 클래스를 만들어 줍니다. 이때 XIB 파일도 함께 생성하도록 옵션을 체크합니다.

스크린샷 2013-10-17 오후 9.33.11

Single View에 해당하는 소스코드, 헤더파일, XIB 파일이 생성되었습니다.

마지막으로 AppDelegate 클래스의 application 함수를 아래와 같이 수정하여 앞에서 생성한 Single View를 Main Interface로 등록합니다.

#import "KGWAppDelegate.h"
#import "KGWViewController.h"

@implementation KGWAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    KGWViewController *viewController = [[KGWViewController alloc] initWithNibName:@"KGWViewController" bundle:nil];
    self.window.rootViewController = viewController;

    [self.window makeKeyAndVisible];
    return YES;
}

니콘 쿨픽스 995

OLYMPUS DIGITAL CAMERA

중고로 구입해서 2003년부터 사용했던 카메라 입니다. 제대로 확인하지 않고 구입했다가 초점이 맞지 않아서 수리비로 8만원을 지출해야 했던 안좋은 기억도 남아 있네요. 이후로 IT 제품을 중고로 구입한 적이 없었던 것 같습니다.

OLYMPUS DIGITAL CAMERA

렌즈를 회전할 수 있는, 지금 다시 봐도 참 독특한 모델입니다. 영입하는 과정에서 우여곡절은 있었지만 이 카메라와 함께 했을때 가장 열정적으로 사진을 찍었던 것 같네요.

OLYMPUS DIGITAL CAMERA

OLYMPUS DIGITAL CAMERA