Skip to content

Instantly share code, notes, and snippets.

why can't I run a dex file in a statically linked linux x64 native elf dalvik vm?

I want to run a dex file in a simple dalvik vm runtime for x86_64…but how?

trying out a simple dvm. there are a few old projects that I couldn't get to work. I will probably try this out at some point: https://github.com/jserv/simple-dvm

dvm

  1. java hello world ugh
#!/usr/bin/env ruby
# coding: utf-8
require 'json'
mapping = JSON.parse(DATA.read)['ascii_to_unicode']
puts mapping.reduce($<.read) { |a, (k,v)| a.gsub(k, v) }
__END__
{
"ascii_to_unicode": {

put this in lambda.sh

#!/usr/bin/env bash

: ${temp_directory=$(mktemp -d "/tmp/demo/example_XXXXXXXXXXXXX")}
: ${filename=$(mktemp "$temp_directory/command_XXXXXXXXXXXX")}
export PATH="$temp_directory:$PATH"

lambda() {
 {
@benolee
benolee / avoiding-hash-lookups-in-ruby.md
Created September 5, 2012 14:20
Avoiding Hash Lookups in a Ruby Implementation

Permalink

Avoiding Hash Lookups in a Ruby Implementation

I had an interesting realization tonight: I'm terrified of hash tables. Specifically, my work on JRuby (and even more directly, my work optimizing JRuby) has made me terrified to ever consider using a hash table in the hot path of any program or piece of code if there's any possibility of eliminating it. And what I've learned over the years is that the vast majority of execution-related (as opposed to data-related, purely dynamic-sourced lookup tables) hash tables are totally unnecessary. Some background might be interesting here.

Hashes are a Language Designer's First Tool

$ rails r 'File.write("./viz.html", Rails.application.routes.router.visualizer)'
$ ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8080, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
$ open "http://localhost:8080/viz.html"
# frozen_string_literal: true
class SafeHash < Hash
def initialize(namespace)
@namespace = namespace
@lock = Concurrent::ReadWriteLock.new
super
merge!({ @namespace => Concurrent::Map.new })
end
class TBQueue
def initialize size
tvar = Concurrent::TVar
@read = tvar.new []
@write = tvar.new []
@rsize = tvar.new 0
@wsize = tvar.new size
end

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@benolee
benolee / fiber_sleep.rb
Created February 4, 2019 21:54 — forked from wycleffsean/fiber_sleep.rb
Fiber Sleep
require 'fiber'
require 'concurrent' # gem install concurrent-ruby
Thread.abort_on_exception = true
class Async
def self.perform(&block)
instance = new
instance.instance_eval(&block)
until instance.dispatched.value.zero? do
unless instance.yields.empty?
@benolee
benolee / gist:dfbedcd2793b4a013f10611526d4847f
Created January 13, 2018 04:30
Ruby's performance tuning way