Uno scrittoio digitale …

17 luglio 2015

js

Archiviato in: code, web — Tag:, — admin @ 22:55

to read …

promisejs
browserify
amcharts

25 giugno 2015

Simple decorator in ruby

Archiviato in: code — Tag:, , , — admin @ 15:15

require 'securerandom'

class EventQueue
  attr_accessor :messages

  def initialize
    @messages = []
  end

  def enqueue(event, args, state)
    @messages << [event, args, state]
  end
end

module Notifier
  def notify_on(event)
    guid = SecureRandom.uuid
    puts "#{guid} ==> #{event}"

    define_method("#{guid}") do |*args|
      @event_queue.enqueue(event, args, :start)
      begin
        result = __send__("#{guid}_#{event}", *args)
      ensure
        @event_queue.enqueue(event, args, :end)
      end
      result
    end

    alias_method "#{guid}_#{event}", event
    alias_method event, "#{guid}"
  end
end

class Store
  extend Notifier

  def initialize(event_queue)
    @event_queue = event_queue
  end

  def order_purchase(user, items)
    ## @event_queue.enqueue(__method__, [user, items], :start)
    do_stuff
    ## @event_queue.enqueue(__method__, [user, items], :end)
  end

  def decrease_inventory(items)
    ## @event_queue.enqueue(__method__, [items], :start)
    do_stuff
    ## @event_queue.enqueue(__method__, [items], :end)
  end

  notify_on :order_purchase
  notify_on :decrease_inventory      

  private

  def do_stuff
    puts "called from #{caller[0]}"
  end
end

puts "#" * 100
queue = EventQueue.new
store = Store.new(queue)
store.order_purchase("alan", ["book", "pen"])
puts "#" * 100
puts "messages = #{queue.messages.inspect}"
puts "#" * 100
puts Store.new(queue).methods.sort - Object.methods.sort

Output:

d02ad4da-a5ec-4ae8-b5ed-53845dd2b391 ==> order_purchase
56df2c28-b927-42d2-8e19-07d115b2c818 ==> decrease_inventory
####################################################################################################
called from /home/alan/Dropbox/clab/Aptana Studio 3 Workspace/2016-06-18/decorator.rb:188:in `d02ad4da-a5ec-4ae8-b5ed-53845dd2b391_order_purchase'
####################################################################################################
messages = [[:order_purchase, ["alan", ["book", "pen"]], :start], [:order_purchase, ["alan", ["book", "pen"]], :end]]
####################################################################################################
56df2c28-b927-42d2-8e19-07d115b2c818
56df2c28-b927-42d2-8e19-07d115b2c818_decrease_inventory
d02ad4da-a5ec-4ae8-b5ed-53845dd2b391
d02ad4da-a5ec-4ae8-b5ed-53845dd2b391_order_purchase
decrease_inventory
order_purchase


16 giugno 2015

Byteman

Archiviato in: code, java — Tag:, , — admin @ 20:59

Byteman is a byte code manipulation and injection tool kit. It allows us to intercept and replace arbitrary parts of Java code to make it behave differently or break it (on purpose):

> get all threads stuck in a certain place and let them continue at the same time (hello race condition)
> throw Exceptions at unexpected locations
> tracing through your code during execution
>change return values

and a lot more things.

Custom T-Shirt

Archiviato in: sapere è potere — Tag: — admin @ 20:54

http://www.cafepress.com/

21 maggio 2015

Appunti

Archiviato in: Senza categoria — admin @ 20:38

http://stackoverflow.com/questions/74674/how-to-do-i-check-cpu-and-memory-usage-in-java

http://www.vogella.com/tutorials/JavaPerformance/article.html

http://javatune.com/post.cfm/15-useful-performance-tools-for-java-environments

http://docs.oracle.com/javase/7/docs/platform/jvmti/jvmti.html

MapDB (java library)

Archiviato in: java — Tag:, , , — admin @ 20:24

MapDB is embedded database engine. It provides java collections backed by disk or memory database store. MapDB has excellent performance comparable to java.util.HashMap and other collections, but is not limited by GC. It is also very flexible engine with many storage backend, cache algorithms, and so on. And finally MapDB is pure-java single 400K JAR and only depends on JRE 6+ or Android 2.1+.

What for?
> In-memory cache with expiration based on time-to-live or maximal size, Redis or EZCache replacement
> Huge indexes
> Persistent data model
> Alternative memory model if you are limited by GC

6 maggio 2015

caniuse html5/css3 feature ?

Archiviato in: Senza categoria — Tag:, — admin @ 09:21

http://caniuse.com/

Grazie Giada D. :D

28 aprile 2015

Ninna nanna per Lorenzo

Archiviato in: Senza categoria — Tag: — admin @ 22:09

ninna nanna

21 aprile 2015

Java7 ForkJoin Framework

Archiviato in: Senza categoria — Tag:, , — admin @ 11:17

For learning about basic parallel operations, there are only 2-4 classes you need to know about:

  • ForkJoinPool: you create exactly one of these to run all your fork-join tasks in the whole program
  • RecursiveTask: you run a subclass of this in a pool and have it return a result; see the examples below
  • RecursiveAction: just like RecursiveTask except it does not return a result
  • ForkJoinTask: superclass of RecursiveTask and RecursiveAction. fork and join are methods defined in this class. You won’t use this class directly, but it is the class with most of the useful javadoc documentation, in case you want to learn about additional methods

import java.util.Random;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask;

public class MaximumFinder extends RecursiveTask {

  private static final int SEQUENTIAL_THRESHOLD = 5;

  private final int[] data;
  private final int start;
  private final int end;

  public MaximumFinder(int[] data, int start, int end) {
    this.data = data;
    this.start = start;
    this.end = end;
  }

  public MaximumFinder(int[] data) {
    this(data, 0, data.length);
  }

  @Override
  protected Integer compute() {
    final int length = end - start;
    if (length < SEQUENTIAL_THRESHOLD) {
      return computeDirectly();
    }
    final int split = length / 2;
    final MaximumFinder left = new MaximumFinder(data, start, start + split);
    left.fork();
    final MaximumFinder right = new MaximumFinder(data, start + split, end);
    return Math.max(right.compute(), left.join());
  }

  private Integer computeDirectly() {
    System.out.println(Thread.currentThread() + ' computing: ' + start
                       + ' to ' + end);
    int max = Integer.MIN_VALUE;
    for (int i = start; i < end; i++) {
      if (data[i] > max) {
        max = data[i];
      }
    }
    return max;
  }

  public static void main(String[] args) {
    // create a random data set
    final int[] data = new int[1000];
    final Random random = new Random();
    for (int i = 0; i < data.length; i++) {
      data[i] = random.nextInt(100);
    }

    // submit the task to the pool
    final ForkJoinPool pool = new ForkJoinPool(4);
    final MaximumFinder finder = new MaximumFinder(data);
    System.out.println(pool.invoke(finder));
  }
}

19 aprile 2015

Measure Anything, Measure Everything

Archiviato in: code — Tag:, — admin @ 16:01

statsd

13 aprile 2015

Run your code online

Archiviato in: code — Tag: — admin @ 10:14

http://runnable.com/

Fatto veramente bene e molto semplice da usare.

19 gennaio 2015

Css

Archiviato in: sapere è potere — admin @ 19:35

purecss
css rule

da rivedere … :D (grazie Giada D.)

16 gennaio 2015

pancake più buoni del mondo

Archiviato in: sapere è potere — admin @ 22:33

primo
secondo

Ottimi entrambi … :D

15 gennaio 2015

A Visual Explanation of SQL Joins

Archiviato in: code — Tag:, — admin @ 18:36

Visto che me le scordo sempre … qua c’è un modo visuale per ricordarsi delle diverse JOIN.

JPA 2.*

Archiviato in: code, java — admin @ 00:41

Solo qualche link utile … a capirci qualcosa :D

guice and jpa
example
wiki

31 dicembre 2014

Clean/flush DNS Cache in linux

Archiviato in: sapere è potere — Tag: — admin @ 14:08

qua

30 dicembre 2014

Rest Principles

Archiviato in: Senza categoria — Tag:, — admin @ 11:49

slide 10 on http://www.slideshare.net/dmytro-chyzhykov/making-java-rest-with-jaxrs-20

GET     /questions          index       list of questions
GET     /questions/new      new         show new question form
POST    /questions          create      create a new question
GET     /questions/:id      show        show a specific question
GET     /questions/:id/edit edit        show form to edit question
PUT     /questions/:id      update      update a specific question
DELETE  /questions/:id      destroy     delete a specific question

27 dicembre 2014

jGroups

Archiviato in: java — Tag:, — admin @ 17:25

qua

JGroups is a toolkit for reliable messaging. It can be used to create clusters whose nodes can send messages to each other. The main features include

> Cluster creation and deletion. Cluster nodes can be spread across LANs or WANs
> Joining and leaving of clusters
> Membership detection and notification about joined/left/crashed cluster nodes
> Detection and removal of crashed nodes
> Sending and receiving of node-to-cluster messages (point-to-multipoint)
> Sending and receiving of node-to-node messages (point-to-point)

27 novembre 2014

Css Layout

Archiviato in: sapere è potere — Tag:, , — admin @ 16:06

here

20 novembre 2014

Force Element To Self-Clear its Children

Archiviato in: sapere è potere — Tag: — admin @ 20:00
.clearfix:after {
     visibility: hidden;
     display: block;
     font-size: 0;
     content: " ";
     clear: both;
     height: 0;
}

Just apply a class=”clearfix” to the parent element.

original page are available here

Articoli precedenti »

Funziona con WordPress