What is sync.Pool in golang and How to use it
sync.Pool (1/2)
Many Go libraries include custom thread-safe free lists, like this:
var objPool = make(chan *Object, 10)
func obj() *Object {
select {
#!/usr/bin/env python | |
def pi(): | |
# Wallis' product | |
numerator = 2.0 | |
denominator = 1.0 | |
while True: | |
yield numerator/denominator | |
if numerator < denominator: | |
numerator += 2 |
DEFAULT ramdisk | |
LABEL ramdisk | |
kernel /casper/vmlinuz | |
append boot=casper initrd=/casper/initrd.img | |
LABEL isotest | |
kernel /casper/vmlinuz | |
append boot=casper integrity-check initrd=/casper/initrd.img | |
LABEL memtest | |
kernel /install/memtest | |
append - |
I'm capturing 802.11 frames - probe requests to be exact. I'm noticing occasional garbled data, so would to incorporate the Frame Check Sequence (FCS) to ensure frame integrity. I'd expect the card to dump failed checksum frames, but maybe this doesn't happen in promisc mode. We can see the FCS in action with tshark like so: | |
# tshark -i mon0 -R 'wlan.fcs' -T fields -e wlan.fcs_good -e wlan.fcs | |
1 0x5c1eecd5 | |
0 0x8d425ccf | |
1 0xb28bb592 | |
1 0xd2cb1bf6 | |
...where wlan.fcs is the calculated checksum, and wlan.fcs_good is the boolean of the result. |
#!/bin/bash | |
if [ "$4" == "" ]; then | |
echo "usage: $0 <local_ip> <remote_ip> <new_local_ip> <new_remote_ip>" | |
echo "creates an ipsec tunnel between two machines" | |
exit 1 | |
fi | |
SRC="$1"; shift | |
DST="$1"; shift |
function construct(constructor, args) { | |
function F() { | |
return constructor.apply(this, args); | |
} | |
F.prototype = constructor.prototype; | |
return new F(); | |
} | |
// Sanboxer | |
function sandboxcode(string, inject) { | |
"use strict"; |
#version 130 | |
#pragma optionNV(unroll all) | |
uint ROTLEFT(in uint a, in int b) { return (a << b) | (a >> (32-b)); } | |
uint ROTRIGHT(in uint a, in int b) { return (a >> b) | (a << (32-b)); } | |
uint CH(in uint x,in uint y,in uint z) { return (x & y) ^ (~x & z); } | |
uint MAJ(in uint x,in uint y,in uint z) { return (x & y) ^ (x & z) ^ (y & z); } | |
uint EP0(in uint x) { return ROTRIGHT(x,2) ^ ROTRIGHT(x,13) ^ ROTRIGHT(x,22); } | |
uint EP1(in uint x) { return ROTRIGHT(x,6) ^ ROTRIGHT(x,11) ^ ROTRIGHT(x,25); } |
What is sync.Pool in golang and How to use it
sync.Pool (1/2)
Many Go libraries include custom thread-safe free lists, like this:
var objPool = make(chan *Object, 10)
func obj() *Object {
select {
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"net" | |
"os" | |
"time" | |
) |
package main | |
import ( | |
"bytes" | |
"encoding/gob" | |
"fmt" | |
) | |
type MyFace interface { | |
A() |
/// <reference path="../tsd/tsd.d.ts" /> | |
import mongoose = require('mongoose'); | |
import passport = require('passport'); | |
interface IUser extends mongoose.Document { | |
provider: string; | |
id: string; | |
authorId: string; | |
displayName: string; |