Skip to content

Instantly share code, notes, and snippets.

View mwanji's full-sized avatar

Moandji Ezana mwanji

View GitHub Profile
@mwanji
mwanji / Java8NonRepeatingString.java
Last active September 18, 2020 09:31
A Java 8 adaptation of code to find the first non-repeated letter in a string. Original found here: http://javahungry.blogspot.com/2013/12/first-non-repeated-character-in-string-java-program-code-example.html#.UsFH_N8Q8ak
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;
import static java.util.function.Function.identity;
public class NonRepeatingLetter {
public static void main(String[] args) {
findFirstNonRepeatingLetter(args[0], System.out::println);
}
@mwanji
mwanji / gist:3849520
Created October 7, 2012 20:37
Tent Catalog App Proposal
App stores are fundamental to the success of modern platforms. Tent should have one, especially as decentralisation makes discovery even more difficult.
Overview
TentCatalog offers discovery, recommendations and one-click installs.
Recommendations are based on what the user's followers/followings have installed (if they have also installed TentCatalog) and what 3rd party catalogs recommend as well.
Flows
User installs TentCatalog.
TentCatalog requests read/write permissions of type https://tent.io/contrib/types/post/installation/v1.0
When user installs another app, TentCatalog is notified
@mwanji
mwanji / tent_access_token_request
Created October 6, 2012 10:58
A successful Tent access token request to tent.is
POST https://javaapiclient.tent.is/tent/apps/evo05h/authorizations
Accept:application/vnd.tent.v0+json
Content-Type:application/vnd.tent.v0+json
{
"code": "a337d62419901973edeb182234a27739",
"token_type": "mac"
}
Had I included an Authorization header, here's what the normalized request would have been:
1349520353
@mwanji
mwanji / oauth_hmac_signing
Created October 5, 2012 10:44
OAuth HMAC signing debugging
timestamp=1349386748510
nonce=kaauue7k
method=POST
uri=/apps/ztfqej/authorizations
host=javaapiclient.tent.is
port=443
mac_key=d9ab6f3b87a8026e54aa5c971bd39e7c
mac_key_id=a:f6f0695f
What the Tent Ruby client says I should get:
@mwanji
mwanji / tent_blog_proposal
Created October 5, 2012 09:27
Tent Blogging App Proposal
Two parts: Viewer and Publisher
Viewer
GET /posts of type Essay (https://tent.io/types/post/essay/v0.1.0)
Is notified when a new Essay is POSTed
Displays them as a blog
Publisher
@mwanji
mwanji / MlkshkRequest.java
Created June 25, 2011 19:20
My naïve attempt at signing a mlkshk request
// apiSecret and accessToken have already been acquired
HttpClient httpClient = AndroidHttpClient.newInstance("");
HttpGet httpGet = new HttpGet(Urls.BASE + "/user");
long utcTimestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis();
String rawNonce = NONCE_SALT + RANDOM.nextInt();
String nonce = rawNonce.substring(0, Math.min(rawNonce.length(), 35));
String normalisedString = accessToken + "\n"
+ utcTimestamp + "\n"
@mwanji
mwanji / MailBuilder.java
Created February 4, 2011 10:09
An example API to rival Groovy's mail API Cf. https://groups.google.com/d/msg/lescastcodeurs/TRONQ4Mo-fE/hKhnr6gMuyMJ for context
package com.moandjiezana.mailapi;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
public String convenient(Object o) {
return lessConvenient(o, "default");
}
public String lessConvenient(Object o, String suffix) {
return o.toString() + suffix;
}
// Unit tests
// assume lessConvenient is already tested
// Pair and SmartMap in action
// Problems:
// 1. this gives a compiler warning: "Type safety : A generic array of Pair<String,String> is created for a
// varargs parameter"
// 2. All second elements of Pairs must be of same type, not even subclasses for it to compile.
public class Example {
public static void main(String[] args) {
SmartMap<String, String> myMap = map(of("key", "value1"), of("key2", "value 1"));
System.out.println(myMap.get("key"));