Skip to content

Instantly share code, notes, and snippets.

@emschwar
emschwar / DateTimeFormatterExample.java
Last active July 31, 2018 01:39
Tests how to parse LocalDateTime with DateTimeFormatter
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateTimeFormatterExample {
public static void main(String []args) {
DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
LocalDateTime time = LocalDateTime.parse("2018-07-30T18:15:34.823", pattern);
System.out.println("parsed time: " + time.toString());
}
@emschwar
emschwar / hello_controller.ex
Last active February 29, 2016 23:55
Hello Controller with redis
defmodule HelloPhoenix.HelloController do
use HelloPhoenix.Web, :controller
def index(conn, _params) do
render conn, "index.html"
end
def show(conn, %{"messenger" => messenger} = params) do
HelloPhoenix.Endpoint.subscribe(self(), "potato")
receive do
class Device
include TempSensors
include LightSensors
end
defmodule Socket do
defstruct socket: nil, transport: nil
use GenServer
def handle_info({:send, payload}, state=%Socket{socket: socket, transport: transport}) do
transport.send(socket, payload)
{ :noreply, state }
end
end
defp deps do
[{:ranch, "1.2.0"},
{:uuid, "~>1.1"},
{:json, "~>0.3.0"},
{:cowboy, "1.0.4"}]
end
defmodule GenServerTestTest do
use ExUnit.Case
doctest GenServerTest
setup do
IO.puts "setup starting"
{ :ok, pid } = GenServerTest.start_link()
IO.puts "setup started"
on_exit fn ->
defmodule Foo do
def hi do
hi_priv(1, 1, 1)
end
defp hi_priv(a, b, c) when a == b, b == c do
IO.puts "hi"
end
end
@emschwar
emschwar / client.rb.diff
Created August 11, 2014 19:10
Proposal for a dummy queue solution
diff --git a/lib/blather/client/client.rb b/lib/blather/client/client.rb
index 6c7fe4e..9e8350b 100644
--- a/lib/blather/client/client.rb
+++ b/lib/blather/client/client.rb
@@ -184,11 +184,7 @@ module Blather
# @private
def receive_data(stanza)
- if handler_queue
- handler_queue << stanza
@emschwar
emschwar / rmodbus.yml
Created January 6, 2012 00:01
updated rmodbus file
"1075553":
f1:
index: 0
ip: 192.168.107.206
"1075281":
f1:
index: 1
ip: 192.168.107.206
@emschwar
emschwar / init.el
Created October 13, 2011 04:31
Testing gh.el with ~/.emacs24.d/init.el
(setq ems-netrc (netrc-parse "~/.netrc"))
(require 'gist)
(setq ems-github-netrc (netrc-machine ems-netrc "github" t))
(setq gist-authenticate-function 'gist-basic-authentication)
(setq gist-user-password (netrc-get ems-github-netrc "password"))