Skip to content

Instantly share code, notes, and snippets.

@nlinker
nlinker / sketch.scala
Created December 26, 2011 03:20 — forked from cho45/sketch.scala
Sandboxed Rhino, Scala
//#! scalac -classpath js.jar sketch.scala && java -classpath .:/opt/local/share/scala/lib/scala-library.jar:js.jar Main #
// http://codeutopia.net/blog/2009/01/02/sandboxing-rhino-in-java/
import java.lang.System
import org.mozilla.javascript._
class SandboxNativeJavaObject (scope: Scriptable, javaObject: Object, staticType: Class[_])
extends NativeJavaObject(scope, javaObject, staticType) {
override def get (name: String, start: Scriptable):Object = null
}
@nlinker
nlinker / gist:3856304
Created October 9, 2012 02:53 — forked from bkimble/gist:1365005
List local memcached keys using Ruby
#!/usr/bin/env ruby
require 'net/telnet'
cache_dump_limit = 100
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
slab_ids = []
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
matches = c.scan(/STAT items:(\d+):/)
slab_ids = matches.flatten.uniq
end
@nlinker
nlinker / SCombinator.scala
Created October 12, 2012 03:44 — forked from folone/SCombinator.scala
Y-Combinator in Scala
/**
* <b>Fixed Point Combinator is:</b>
* Y = λf.(λx.f (x x)) (λx.f (x x))
*
* <b>Proof of correctness:</b>
* Y g = (λf . (λx . f (x x)) (λx . f (x x))) g (by definition of Y)
* = (λx . g (x x)) (λx . g (x x)) (β-reduction of λf: applied main function to g)
* = (λy . g (y y)) (λx . g (x x)) (α-conversion: renamed bound variable)
* = g ((λx . g (x x)) (λx . g (x x))) (β-reduction of λy: applied left function to right function)
* = g (Y g) (by second equality) [1]
@nlinker
nlinker / gist:3877185
Created October 12, 2012 03:46
test big or litte endian
int bigOrLitteEndian() {
short int word = 0x0001;
char *byte = (char *) &word;
return (byte[0] ? 1 : 0);
}
@nlinker
nlinker / apache.erl
Created October 12, 2012 03:47
Script to check how many connections can Apache server survive
#!/usr/bin/env escript
-mode(compile).
-compile(export_all).
main([]) -> io:format("Usage: ~s URL [Count=1000]~n", [escript:script_name()]);
main([URL]) -> main([URL,"100"]);
main([URL,C] ) -> manage_workers(URL, [start_worker(URL, N) || N <- lists:seq(1,list_to_integer(C))]), ok.
@nlinker
nlinker / amo_rabbit_prod_report.php
Created October 31, 2012 15:54 — forked from oremj/amo_rabbit_prod_report.php
Rabbit ganglia metrics
<?php
/* Pass in by reference! */
function graph_amo_rabbit_prod_report ( &$rrdtool_graph ) {
global $context,
$hostname,
$mem_shared_color,
$mem_cached_color,
$mem_buffered_color,
@nlinker
nlinker / gist:4057857
Created November 12, 2012 06:47 — forked from invalidusrname/Vagrantfile
Connecting between VMs with vagrant
config.vm.define :puppet do |app_config|
app_config.vm.customize ["modifyvm", :id, "--name", "puppet", "--memory", "512"]
app_config.vm.box = "precise_with_puppet"
app_config.hosts.name = 'puppet'
app_config.vm.host_name = 'puppet'
app_config.vm.forward_port 22, 2222, :auto => true
app_config.vm.forward_port 80, 4561
app_config.vm.network :hostonly, "33.13.13.01"
app_config.vm.provision :shell do |shell|
shell.path = "../puppet_master_setup.sh"
@nlinker
nlinker / AA.md
Created February 4, 2013 00:28 — forked from sadache/AA.md

Is socket.push(bytes) all you need to program Realtime Web apps?

One of the goals of Play2 architecture is to provide a programming model for what is called Realtime Web Applications.

Realtime Web Applications

Realtime Web Applications are applications that make use of Websockets, Server Sent Events, Comet or other protocols offering/simulating an open socket between the browser and the server for continuous communication. Basically, these applications let users work with information as it is published - without having to periodically ping the service.

There are quite a few web frameworks that target the development of this type of application: but usually the solution is to simply provide an API that allows developers to push/receive messages from/to an open channel, something like:

using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web.Mvc;
using Umbraco.Web.Routing;
namespace Our.Umbraco
{
public class MyApplication : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
<?xml version="1.0" encoding="utf-8" ?>
<NotFoundHandlers>
<notFound assembly="umbraco" type="SearchForAlias" />
<notFound assembly="umbraco" type="SearchForTemplate"/>
<notFound assembly="umbraco" type="SearchForProfile"/>
<notFound assembly="CatchAllRouteHandler" namespace="Our" type="CatchAll"/>
<notFound assembly="umbraco" type="handle404"/>
</NotFoundHandlers>