/images/art2.png

Redis overview

Installation

For mac

sudo brew install redis-server

open redis server

redis-server

test is work or not

redis-cli ping

basic command

ECHO 'hello word

QUIT
SET foo 100

GET foo // 100

SET bar 'hello world'

GET bar // hello world

INCR foo // 101

DECR foo // 100

EXISTS foo // 1

EXISTS foo1 // 0

DEL bar

EXISTS bar // 0

GET bar //(nir)

FLUSHALL // all empty

SET server:name someserver

GET server:name // "someserver"

SET server:port 8000

GET server:port

SET greeting "Hello world"

GET greeting

EXPIRE greeting 50  // set expirations to 50 second

TTL greeting

SETEX greeting 30 "hello world" // set value and expiration

PERSIST greeting // key will not expire

TTL greeting // -1

MSET key1 "hello" key2 "world"

APPEND key1 " world"

RENAME key1 greeting

LPUSH people "Brad" // 1

LPUSH people "Jen" // 2

LPUSH people "Tom" // 3

LRANGE people 0 -1 // return all // Tom Jen Brad

LRANGE people 1 2 // Jen Brad

RPUSH people "Harry"

LRANGE people 0 -1 // Tom Jen Brad Harry

LLEN people // 4

RPOP people // Harry

LPOP people

LINSERT people BEFORE "Brad" "TOM"

LRANGE people 0 -1 // Jen Tom Brad

SADD cars "Ford"

SADD cars "Honda"

SADD cars "BMW"

SISMEMBER cars "Ford" // 1

SISMEMBER cars "Chevy" // 0

SMEMBER cars // Honda BMW Ford

SCARD cars // 3

SMOVE cars mycars "Ford"

SMEMBER cars // Honda BMW

SMEMBER mycars // Ford

SRAM cars "BMW"

SMEMBER cars // Honda

ZADD users 1980 "Brad"

ZADD users 1975 "Jen"

ZADD users 1990 "Mike"

ZADD users 1990 "Kate"

ZRANK users "Mike" // 3

ZRANK users "Jen" // 0

ZRANK users "Brad" // 1

ZRANGE users 0 -1 // Jen Brad Kate Mike

ZINCRBY users 1 "Jen" // 1976

HSET user:brad name "Brad"

HSET user:brad email "brad@gmail.com"

HGET user:brad name

HGET user:brad email

HGETALL user:brad

HMSET user:john name "Jen" email "jen@yahoo.com" age "25"

HGETALL user:john

HKEYS user:john

HVAL user:john

HINCERBY user:john age 1 // 26

HDEL user:john age // 1

HLEN user:john // 2

SAVE

Some cool websites archive

Development setting up for Mac

This guide covers the basics of setting up a development environment on a new Mac.

https://sourabhbajaj.com/mac-setup/

shapeCatcher

Draw a character and find the ASCII code

http://shapecatcher.com/index.html

draw.io

Draw diagram online

https://www.draw.io

regular expression

Good online tool to test and learn regular expression

https://regexr.com

100 front end component design

100 react component design challenge

https://www.florin-pop.com/blog/2019/09/100-days-100-projects/

bootswatch

Several bootstrap scheme.

React overview

Init react

Commend

npx create-react-app .

npx means you use this package but don’t download it.

or with redux

npx create-react-app my-app --template redux

life cycle

Class component lifecycle

Function component method

shouldComponentUpdate()

Run before render() to check this component need to render or not.

Concurrent Programming Course note 4

Monitor

signal condition –> waiting monitor –> signaling

producer and consumer with a buffer whose size is one


monitor PC {
    Object buffer;

    void produce(Object o){
        if(buffer != null){ // while
            empty.wait();
        }
        buffer = o;
        full.signal();
    }

    Object consume() {
        if(buffer == null) // while
            full.wait();
        Object temp = buffer;
        empty.signal();
        return temp;
    }
}

Semaphore

// Assumption: E < S < W (Signal and urgent wait)
monitor Semaphore {
    int permit;

    void acquire() {
        if(permit == 0){
            permitsAvailable.wait();
        } else {
            permit--;
        }
    }

    void release(){
        if(!permitAvailable.isEmpty()){
            permitsAvailable.signal();
        } else{
            permit++;
        }
    }
}

readers and writers

assume start first and stop

All algorithm in C++

Content

Algorithm Overview

* –> new feature from C++11

Algorithm NameUsageMutating?Head FileComplexity
accumulateAccumulate values in rangeNnumericO(n)
adjacent_differenceCompute adjacent difference of range and return to another placeNnumericO(n)
adjacent_findFind first equal adjacent elements in rangeNalgorithmO(n)
all_of*Test condition on all elements in rangeNalgorithmO(n)
any_of*Test if any element in range fulfills conditionNalgorithmO(n)
binary_searchTest if value exists in sorted sequenceNalgorithmOn average O(logn + 2). On non-random-access iterator is O(n)
copyCopy range of elementsN(copy)algorithmO(n)
copy_backwardCopy range of elements backwardN(copy)algorithmO(n)
copy_if*Copy certain elements of rangeN(copy)algorithmO(n)
copy_n*Copies the first n elements from the range beginningN(copy)algorithmO(n)
countCount appearances of value in rangeNalgorithmO(n)
count_ifReturn number of elements in range satisfying conditionNalgorithmO(n)
equalTest whether the elements in two ranges are equalNalgorithmO(n)
equal_rangeGet sub range of equal elementsNalgorithmO(2logn + 1) for random access iterator, otherwise O(n)
fillFill range with valueYalgorithmO(n)
fill_nAssigns val to the first n elements of the sequence pointed by firstYalgorithmO(n)
findFind the first element in rangeNalgorithmO(n)
find_endFind last subsequence in rangeNalgorithmO(m*(1+n-m))
find_first_ofReturns an iterator to the first element in the range [first1,last1) that matches any of the elements in [first2,last2)NalgorithmO(nm)
find_ifFind the first element in range in some conditionNalgorithmO(n)
find_if_not*Find the first element in range in some conditionNalgorithmO(n)
for_eachApply function to rangeNalgorithmO(n)
generateAssigns the value returned by successive calls to gen to the elements in the range [first,last)YalgorithmO(n)
generate_nAssigns the value returned by successive calls to gen to the first n elements of the sequence pointed by firstYalgorithmO(n)
includesTest whether sorted range includes another sorted rangeNalgorithmO(n)
inner_productCompute cumulative inner product of rangeNnumericO(n)
inplace_mergeMerge consecutive sorted rangesYalgorithmO(n) if extra memory is available, otherwise is O(nlogn)
iotaStore increasing sequenceYnumericO(n)
is_heap*Test if range is heapNalgorithmO(n)
is_heap_until*Find first element not in heap order.NalgorithmO(n)
is_partitioned*Test whether range is partitionedYalgorithmO(n)
is_permutation*Compares the elements in the range [first1,last1) with those in the range beginning at first2, and returns true if they just different permutationNalgorithmO(n)
is_sorted*Check whether range is sortedNalgorithmO(n)
is_sorted_until*Find first unsorted element in rangeNalgorithmO(n)
iter_swapSwaps the elements pointed to by a and bYalgorithmO(1)
lexicographical_compareCompare two range lexicographically.NalgorithmO(n)
lower_bondReturn iterator to lower boundNalgorithmO(logn + 1) for random access iterator, otherwise O(n)
make_heapMake heap from rangeYalgorithmO(3n)
maxReturns the largest of a and b. If both are equivalent, a is returned.NalgorithmO(1)
max_elementReturn largest element in rangeNalgorithmO(n)
mergeMerge sorted rangesYalgorithmO(n)
minReturns the smallest of a and b. If both are equivalent, a is returned.NalgorithmO(1)
minmax*Return smallest and largest elements from give 2 value or initializerNalgorithmO(1)
minmax_element*Return smallest and largest elements in rangeNalgorithmO(n)
min_elementReturn smallest element in rangeNalgorithmO(n)
mismatchReturn first position where two ranges differNalgorithmO(n)
move*Move range of elementsYalgorithmO(n)
move_backward*Move range of elements backwardYalgorithmO(n)
next_permutationRearranges the elements in the range [first,last) into the next lexicographically greater permutationYalgorithmO(n)
none_of*Test if no elements fulfill conditionNalgorithmO(n)
nth_elementFind the nth element and put it the exact palce.(quick select)YalgorithmO()
partial_sortPartially sort elements in range while the remaining elements are left without any orderYalgorithmO(mlogn)
partial_sort_copyCopy and partially sort rangeY (if in-place)algorithmO(mlogn)
partial_sumCompute partial sums of range and return to another placeNnumericO(n)
partitionPartition range in two and the iterator returned points to the first element of the second group.YalgorithmO(n)
partition_copy*Partition range into twoNalgorithmO(n)
partition_point*Get partition point and Returns an iterator to the first element in second partNalgorithmO(logn + 2)
pop_heapPop element from heap range. Range shrink and value is at end.YalgorithmO(logn)
prev_permutationRearranges the elements in the range [first,last) into the previous lexicographically-ordered permutation.YalgorithmO(n)
push_heapPush element into heap range. Range extendYalgorithmO(logn)
random_shuffleRandomly rearrange elements in rangeYalgorithmO(n)
removeRemoved element equal to val and returns an iterator to the new end of that range.YalgorithmO(n)
remove_copyRemove and copy to new placeYalgorithmO(n)
remove_copy_ifRemove in a given condition and copyYalgorithmO(n)
remove_ifRemove in a given conditionYalgorithmO(n)
replaceAssigns new_value to all the elements that compare equal to old_valueYalgorithmO(n)
replace_copyReplace and copyYalgorithmO(n)
replace_copy_ifReplace in a given condition and copyYalgorithmO(n)
replace_ifReplace in a given conditionYalgorithmO(n)
reverseReverses the order of the elements in the range [first,last)YalgorithmO(n)
reverse_copyCopies the elements in [first,last) but in reverse orderYalgorithmO(n)
rotateRotates the order of the elements and middle becomes the new first elementYalgorithmO(n)
rotate_copyRotate and copyYalgorithmO(n)
searchSearch range for subsequenceNalgorithmO(n*m)
search_nSearch range for n continue elementsNalgorithmO(n)
set_differenceDifference of two sorted rangesN(copy)algorithmO(2(n+m)-1)
set_intersectionIntersection of two sorted rangesN(copy)algorithmO(2(n+m)-1)
set_symmetric_differenceSymmetric difference of two sorted rangesN(copy)algorithmO(2(n+m)-1)
set_unionUnion of two sorted rangesN(copy)algorithmO(2(n+m)-1)
shuffle*Randomly rearrange elements in range using generatorYalgorithmO(n)
sortSort elements in rangeYalgorithmO(nlogn)
sort_heapSort elements of heapYalgorithmO(nlogn)
stable_partitionPartition range in two - stable orderingYalgorithmO(n) with enough space. Otherwise O(nlogn)
stable_sortSort elements preserving order of equivalentsYalgorithmO(nlogn) with enough space, otherwise O(nlognlogn)
swapExchanges the values of a and bYalgorithmO(1)
swap_rangesExchanges a range of valueYalgorithmO(n)
transformTransform rangeYalgorithmO(n)
uniqueRemove consecutive duplicates in rangeYalgorithmO(n)
unique_copyCopy range removing duplicatesYalgorithmO(n)
upper_bondReturn iterator to upper bound. Since [first, last), the value pointed by the iterator must larger than valNalgorithmO(logn + 1) for random access iterator, otherwise O(n)

Copy

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[])
{
	vector<int> iv = {1,2,3,4,5,6};

	vector<int> iv2(6);
	copy(iv.begin(), iv.end(), iv2.begin());
	// iv2: 1 2 3 4 5 6

	vector<int> iv3(3);
	copy_if(iv.begin(), iv.end(), iv3.begin(), [](int a){return a % 2 == 0;});
	// iv3: 2 4 6

	vector<int> iv4(5);
	copy_n(iv.begin(), 5, iv4.begin());
	// iv4: 1 2 3 4 5 6

	vector<int> iv5(6);
	copy_backward(iv.begin(), iv.end(), iv5.end());
	// iv5: 1 2 3 4 5 6

	return 0;
}

Back to top

SASS (SCSS) features

SCSS features

Variables

$font-stack: Helvetica, sans-serif;
$primary-color: #333;

body {
    font: 100% $font-stack;
    color: $primary-color;
}

Operator

.container {
    width: 100%;
}

article[role='main'] {
    float: left;
    width: 600px / 960px * 100%;
}

article[role='complementary'] {
    float: right;
    width: 300px / 960px * 100%;
}

String interpolation

$name: foo;
$attr: border;
p.#{$name} {
    #{$attr}-color: blue;
}

This is compile to: