Skip to content

Instantly share code, notes, and snippets.

View bithavoc's full-sized avatar

Johan Hernandez bithavoc

View GitHub Profile
@bithavoc
bithavoc / dparsingjsonvalueretain.d
Last active October 21, 2016 13:15
Demo of Parsing objects using instances of JSONValue
/*
* http://johan.heapsource.com
*/
import std.stdio;
import std.json;
JSONValue doc;
void main() {
/*
* http://johan.heapsource.com
*/
import std.stdio;
import std.json;
void main() {
JSONValue v = parseJSON(q{
{"a":2, "b":{"c":20}}
/*
* http://johan.heapsource.com
*/
import std.stdio;
import std.json;
void main() {
JSONValue * v = new JSONValue;
*v = parseJSON(q{
@bithavoc
bithavoc / couched.d
Created February 9, 2014 15:50
couche.d proposal
import heaploop.looping;
import couched;
import std.json;
void main() {
loop ^^ {
auto client = new CouchedClient("http://127.0.0.1:5984");
client.databases.ensure("albums");
CouchedDatabase db = client.databases["albums"];
import std.json;
...
JSONValue doc;
assert(doc == JSONValue.init); // always true, doc was never assigned.
/**
JSON type enumeration
*/
enum JSON_TYPE : byte
{
/// Indicates the type of a $(D JSONValue).
STRING,
INTEGER, /// ditto
UINTEGER,/// ditto
FLOAT, /// ditto
import std.stdio : writeln;
import std.json;
void main() {
JSONValue[] values = [parseJSON("28"),
parseJSON("\"hello world\""),
parseJSON(q{{"name": "Johan"}}),
parseJSON("[2,3]"),
parseJSON("true"),
parseJSON("false"),
500 - Internal Server Error
Internal Server Error
Internal error information:
core.exception.AssertError@../../../opt/vibe/source/vibe/core/drivers/libevent2_tcp.d(120): Trying to acquire a TCP connection that is currently owned.
----------------
./dub-registry(_d_assert_msg+0x45) [0xa12b0d]
./dub-registry(void vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.acquire()+0xe3) [0x7a0b27]
./dub-registry(void vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.close()+0x6e) [0x7a0df2]
import std.stdio;
import mime;
void main() {
/*Proposal for Mime type package for D*/
auto mime = Mime.fromExtension(".midi");
assert(mime.description == "MIDI Audio");
mime = Mime.fromType("application/x-midi");
assert(mime.description == "MIDI Audio");
public string WebGetString(Uri endpoint, string path, params WebParam[] queryParams)
{
System.Net.WebClient client = new System.Net.WebClient();
StringBuilder relativePath = new StringBuilder(path);
var filteredParams = (from p in queryParams where p.Value != null select p).ToArray();
if (filteredParams != null && filteredParams.Length > 0)
{
relativePath.Append("?");
foreach (var param in filteredParams)
{