Skip to content

Instantly share code, notes, and snippets.

@cowlike
cowlike / fold.erl
Last active September 29, 2015 02:17
foldl with predefined function
-module(fold_test).
-export([do_fold/0]).
do_fold() -> lists:foldl(fun(T,Acc) -> foo(T,Acc) end, [], [1,2,3]).
foo(T, Acc) -> [T | Acc].
[this fails with a parse error]
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SearchRequest xmlns="http://www.example.com/account">
<UserId>User1</UserId>
</SearchRequest>
</soap:Body>
</soap:Envelope>
[this works]
@cowlike
cowlike / linqXml.cs
Last active September 30, 2015 05:07
from: www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Sample RSS Feed"),
new XElement("rss",
new XAttribute("version", "2.0"),
new XElement ("channel",
new XElement("title", "RSS Channel Title"),
new XElement("description", "RSS Channel Description."),
@cowlike
cowlike / directoryExample.cs
Last active October 2, 2015 03:28
ldap read
foreach (SearchResult dnResult in rootSearcher.FindAll())
{
EmailAddresses.Add(dnResult.Properties["mail"].ToString());
}
foreach (SearchResult dnResult in rootSearcher.FindAll())
{
foreach (string dnName in dnResult.Properties.PropertyNames)
{
using System;
namespace extensions
{
class Foo
{
private int myInt = 3;
virtual public int MyInt
{
get { return myInt; }
@Grab(group='com.unboundid', module='unboundid-ldapsdk', version='2.3.1')
import com.unboundid.ldap.sdk.*
def mr = new ModifyRequest('cn=jrandom,ou=accounts,dc=somewhere,dc=com',
[new Modification(ModificationType.REPLACE, 'msDS-UserAccountDisabled', 'TRUE'.bytes)])
LDAPConnection.metaClass.modify = {ModifyRequest req -> println req; null}
LDAPConnection c = new LDAPConnection()
@Grab(group='com.unboundid', module='unboundid-ldapsdk', version='2.3.1')
import com.unboundid.ldap.sdk.*
LDAPConnection.metaClass.bind = {SimpleBindRequest req -> println req; null}
LDAPConnection c = new LDAPConnection()
c.bind(new SimpleBindRequest())
(ns my.Class
(import (a.b.c Thing))
(:gen-class
:methods [^{:static true} [foo [Thing] String]]))
(defn -foo [t] "foo")
@cowlike
cowlike / destructure.clj
Created July 20, 2015 23:22
destructuring
(let [a-map {:l1 {:x \y :l2 {:l3 {:a 1 :b 2}}}}
{{val-x :x {{:keys [a b]} :l3} :l2} :l1} a-map]
(prn b val-x))
;; 2 \y
import java.util.*;
public class Main {
static OptionalDouble toDouble(String s) {
OptionalDouble val = OptionalDouble.empty();
try {
val = OptionalDouble.of(Double.parseDouble(s));
}
catch (NumberFormatException e) {
//leave empty