This file contains hidden or 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" | |
"strconv" | |
"strings" | |
) | |
func toUin64(data, sep string) []uint64 { | |
fields := strings.Split(data, sep) |
This file contains hidden or 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" | |
"net/url" | |
"github.com/streadway/amqp" | |
) | |
// InitByConfigServices loads configuration from a conf file |
This file contains hidden or 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 "C" | |
import ( | |
"fmt" | |
"plugin" | |
) | |
func main() { | |
p, err := plugin.Open("./plugins.so") |
This file contains hidden or 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 ( | |
"crypto/rand" | |
"fmt" | |
"golang.org/x/crypto/scrypt" | |
) | |
func main() { |
This file contains hidden or 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" | |
"runtime" | |
"time" | |
) | |
// Thread stages | |
const ( |
This file contains hidden or 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
# help to avoid path traversal, and execution of anything on a machine | |
# due to file name | |
def escape_file_name(name) | |
# regex is a s follows: | |
# if it's the begining of the string, or there is no escape char | |
# for the following chars, | |
# add an escape for that char | |
name.gsub(/(^|[^\\])([\s\!\'\"#$&\^\*\`\/\(\)\[\]\?\{\}\|\~])/) do |match| | |
"\\#{match[1]}" | |
end |
This file contains hidden or 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
#!/bin/sh | |
func() { | |
for p in $(echo /tmp/*); do | |
f=$(basename -a "$path") | |
echo $f | |
done | |
} |
This file contains hidden or 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
/* ... */ | |
const char * get_message(void * payload) { | |
payload_t *data = payload; | |
if (!data->len > MIN_PAYLOAD_LEN) { | |
return null; | |
} | |
return sprintf("%s%s", data->name, data->content); | |
} |
This file contains hidden or 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
require 'benchmark' | |
require 'securerandom' | |
N = 1_000_000 | |
REGEX = /^(abc|Abc|ABC)/ | |
def gen_randstr(len = 24) | |
SecureRandom.base64(len) | |
end |
This file contains hidden or 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
require 'benchmark' | |
N = 1_000_000 | |
REGEX = /^abc/ | |
STR = 'abc are letters'.freeze | |
Benchmark.bm(13) do |x| | |
x.report('start_with?') do | |
N.times do | |
STR.start_with?('abc') |