Skip to content

Instantly share code, notes, and snippets.

diff --git a/src/crystal/system/random.cr b/src/crystal/system/random.cr
index e03cc6ca6..745d0300d 100644
--- a/src/crystal/system/random.cr
+++ b/src/crystal/system/random.cr
@@ -11,7 +11,7 @@ module Crystal::System::Random
end
{% if flag?(:linux) %}
- require "./unix/getrandom"
+ require "./unix/urandom"
@rdp
rdp / addrinfo.diff
Created November 16, 2019 06:04
crystal lang #8263
diff --git a/src/socket/addrinfo.cr b/src/socket/addrinfo.cr
index 25e046cda..0ac8867ae 100644
--- a/src/socket/addrinfo.cr
+++ b/src/socket/addrinfo.cr
@@ -82,12 +82,12 @@ class Socket
class Error < Socket::Error
getter error_code : Int32
- def self.new(error_code)
- new error_code, "getaddrinfo: #{String.new(LibC.gai_strerror(error_code))}"
crystal make Makefile:68: *** Could not locate llvm-config, make sure it is installed and in your PATH, or set LLVM_CONFIG. Stop.
this meant "llvm isn't linked in after it's installed" "it's "keg only" or whatever homebrew calls it" so you have to link it or manually use it, this:
$ find /usr -name llvm-config
/usr/local/Cellar/llvm@8/8.0.1/bin/llvm-config
$ PATH=/usr/local/Cellar/llvm@8/8.0.1_1/bin/:$PATH make
@rdp
rdp / webby.rb
Created November 11, 2019 05:05
require 'webrick'
server = WEBrick::HTTPServer.new :Port => 8000
server.mount_proc '/' do |req, res|
if req.path != "/"
address = "taobao.com"
else
address = "facebook.com"
end
require "socket"
lib C
# In C: double cos(double x)
fun sleep(value : UInt32) : UInt32
end
spawn {
loop {
TCPSocket.new("facebook.com",80,0.1,0.1).close
STDOUT.print "."
@rdp
rdp / gist:7162414833becbee5919cda855f1cb86
Created October 31, 2019 17:00
cat vs direct on an NFS mount
$ ls -lh a
-rw-rw-r-- 1 x x 10G Oct 31 16:52 a
$ time grep abc < a
real 0m20.633s
user 0m9.745s
sys 0m10.837s
$ time grep abc a
How to get the build version by having maven create a file with the "build.timestamp" etc. in it:
You can set it yourself by filtering a "resource" properties file that declares it, then read it as a resource, a la:
String retrieveVersionFromResource() throws IOException {
try (InputStream br = getClass().getResourceAsStream("/auto-version.txt")) { // maven pom.xml specifies to setup auto-version.txt with some values for us
Properties props = new Properties();
props.load(br);
return "build_version=" + props.get("project_version") + " " + props.get("build_date");
}
@rdp
rdp / gist:b3b63890f2d85e91999ac7a995b4443b
Created February 14, 2019 03:29
poor man's profiler of hung crystal app
26 ??,??,_Unwind_Backtrace,unwind,initialize,new,raise,unbuffered_close,close,process,process,handle_client,->,run,->,??
12 ??,__GI___dl_iterate_phdr,_Unwind_Find_FDE,??,_Unwind_Backtrace,unwind,initialize,new,raise,unbuffered_close,close,process,process,handle_client,->,run,->,??
10 ??,??,_Unwind_RaiseException,__crystal_raise,raise,unbuffered_close,close,process,process,handle_client,->,run,->,??
10 __kernel_vsyscall,recv,unbuffered_read,fill_buffer,read,->,BIO_read,??,??,??,SSL_shutdown,unbuffered_close,close,process,process,handle_client,->,run,->,??
7 ??,??,??,_Unwind_RaiseException,__crystal_raise,raise,unbuffered_close,close,process,process,handle_client,->,run,->,??
5 includes?,->,_Unwind_Backtrace,unwind,initialize,new,raise,unbuffered_close,close,process,process,handle_client,->,run,->,??
5 ??,__GI___dl_iterate_phdr,_Unwind_Find_FDE,??,??,_Unwind_RaiseException,__crystal_raise,raise,unbuffered_close,close,process,process,handle_client,->,run,->,??
4 ??,_Un
diff --git a/cross_compile_ffmpeg.sh b/cross_compile_ffmpeg.sh
index dda8ccd..29736f1 100755
--- a/cross_compile_ffmpeg.sh
+++ b/cross_compile_ffmpeg.sh
@@ -380,11 +380,18 @@ do_configure() {
if [ -f bootstrap ]; then
./bootstrap # some need this to create ./configure :|
fi
- if [[ ! -f $configure_name && -f bootstrap.sh ]]; then # fftw wants to only run this if no configure :|
- ./bootstrap.sh
@rdp
rdp / test.c
Created January 30, 2019 04:15
test if libvmaf works ffmpeg from config.log
#include <libvmaf.h>
#include <stdint.h>
long check_compute_vmaf(void) { return (long) compute_vmaf; }
int main(void) { int ret = 0;
ret |= ((intptr_t)check_compute_vmaf) & 0xFFFF;
return ret; }