Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / zmq_websocket_gateway.py
Created April 24, 2012 08:25 — forked from saghul/zmq_websocket_gateway.py
A ZeroMQ - WebSocket gateway
# coding=utf8
# Copyright (C) 2011 Saúl Ibarra Corretgé <saghul@gmail.com>
#
import hashlib
import os
import re
import socket
import struct
@alco
alco / producer_multicast.py
Created April 24, 2012 08:25 — forked from saghul/producer_multicast.py
ZMQ multicast producer example
# producer
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.setsockopt(zmq.LINGER, 0) # discard unsent messages on close
socket.connect('epgm://239.192.1.1:5000')
while True:
@alco
alco / index.html
Created April 24, 2012 08:25 — forked from saghul/index.html
Simple HTML WebSocket client for the ZeroMQ gateway
<html>
<head>
<title>ZWS Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script language='javascript'>
$(document).ready(function() {
var ws = new WebSocket("ws://localhost:9999/test");
ws.onmessage = function(evt) {
$('#output').append(evt.data+'<br />');
@alco
alco / gist:3731366
Created September 16, 2012 07:03 — forked from james4k/gist:3730918
package main
import "fmt"
import "math"
func FastInvSqrt(x float32) float32 {
xhalf := float32(0.5) * x
i := math.Float32bits(x)
i = 0x5f3759df - i>>1
x = math.Float32frombits(i)
package main
import (
m "math"
)
const LIMIT = 100
func main() {
// They don't recomend working with raw arrays, so use a slice
@alco
alco / client.go
Last active December 16, 2015 15:29 — forked from gmile/client.go
package main
import "net"
import "bufio"
func main() {
conn, err := net.Dial("tcp", ":8080")
if err != nil {
println("There was an error:", err)
@alco
alco / client.go
Last active December 16, 2015 16:49 — forked from gmile/client.go
package main
import "net/rpc"
type Region struct {
X, Y int
}
func main() {
client, _ := rpc.Dial("tcp", ":8080")
@alco
alco / gist:6353899
Last active December 21, 2015 19:20 — forked from chrismccord/gist:6349128
defrecord User, email: nil
defimpl Access, for: User do
def access(record, attr) do
index = record.__record__(:index, attr)
elem(record, index)
end
end
user = User.new(email: "foo@bar.com")
@alco
alco / crays.cpp
Created September 24, 2013 14:03 — forked from kidoman/crays.cpp
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef int i; //Save space by using 'i' instead of 'int'
typedef float f; //Save even more space by using 'f' instead of 'float'
//Define a vector class with constructor and operator: 'v'
struct v {
f x,y,z; // Vector has three float attributes.
@alco
alco / macro.ex
Last active December 26, 2015 07:59 — forked from 5HT/gist:7117914
# If you need to invoke a macro at the top level of a module definition (i.e. not inside a "def"),
# extract it into another module
defmodule N2OMACRO do
defmacro element_base(mod) do quote do [ancestor: :element, module: unquote(mod), id: :undefined,
actions: [], class: [], style: [], source: [],
data_fields: [], aria_states: [], body: [], role: [],
tabindex: 0, show_if: false, html_tag: :undefined, title: []] end end
end