The default Go implementation of
sync.RWMutex does not scale well
to multiple cores, as all readers contend on the same memory location
when they all try to atomically increment it. This gist explores an
n
-way RWMutex, also known as a "big reader" lock, which gives each
CPU core its own RWMutex. Readers take only a read lock local to their
core, whereas writers must take all locks in order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" /> | |
<title>Sewise Player</title> | |
<style type="text/css"> | |
body{ | |
margin: 0px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int binary_search(int *a, int length, int target) | |
{ | |
int left = 0; | |
int right = length - 1; | |
int middle = 0; | |
while (left <= right) | |
{ | |
middle = (left + right) >> 1; |
A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."
- Does the design expect failures to happen regularly and handle them gracefully?
- Have we kept things as simple as possible?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define ERROR_DATA -999999 | |
typedef struct { | |
int *pData; | |
int length; | |
int top; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "sort" | |
type BySortIndex []int | |
func (a BySortIndex) Len() int { return len(a) } | |
func (a BySortIndex) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | |
func (a BySortIndex) Less(i, j int) bool { |
ngClass
指令允许我们基于表达式的结果为指定 DOM 对象添加/删除 CSS class
例如,若 expression
为 true
,为元素添加 class="class-a"
:
<div ng-class="{ class-a: expression }"></div>
同时,多个 class 可以分别基于多个表达式的结果:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL: http://stackoverflow.com/questions/24864956/angularjs-how-do-i-access-directive-attribute-in-controller | |
app.directive('rating', [function () { | |
return { | |
restrict: 'E', | |
scope: { | |
maxStars: '=', | |
url: '@' | |
}, | |
controller: 'ratingController' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include $(GOROOT)/src/Make.inc | |
GOFMT=gofmt -spaces=true -tabindent=false -tabwidth=4 | |
all: | |
$(GC) jsontest.go | |
$(LD) -o jsontest.out jsontest.$O | |
format: | |
$(GOFMT) -w jsontest.go |