Skip to content

Instantly share code, notes, and snippets.

@sguzman
sguzman / template-template-param.c++
Created April 16, 2015 21:30
My first use of template template parameters
template <class C, template <class C> class A, template <class C> class B>
static inline void assertEquals(const A<C>& expected, const B<C>& actual) {
auto success = 0, failure = 0;
for (auto iter1 = expected.cbegin(), iter2 = actual.cbegin();
iter1 != expected.cend() && iter2 != actual.cend(); ++iter1, ++iter2) {
if (Test::assertEquals<C>(*iter1, *iter2)) {
++success;
} else {
++failure;
@sguzman
sguzman / notwoSimilar.cxx
Created May 6, 2015 21:17
Function returns true or false if string can be arranged in such a way so that no two adjacent characters are simliar. If so, do it.
#pragma once
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <string>
#include <utility>
#include <vector>
using ull = unsigned long long;
@sguzman
sguzman / factor-num.go
Created May 11, 2015 08:06
factor 27^140... of course, its only prime factor is 3
package main
import (
"fmt"
"math/big"
//util "github.com/cznic/mathutil"
)
func Copy(from *big.Int) (*big.Int) {
stubby := big.NewInt(1)
@sguzman
sguzman / TLSSocketFactory.java
Created February 9, 2016 00:40
Custom SSLSocketFactory Implementation to enable tls 1.1 and tls 1.2 - thanks to https://github.com/fkrauthan
package com.santaba.zuora.tls;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.net.InetAddress;
@sguzman
sguzman / TLSSocketFactory.java
Created February 9, 2016 00:48 — forked from fkrauthan/TLSSocketFactory.java
Custom SSLSocketFactory Implementation to enable tls 1.1 and tls 1.2 for android 4.1 (16+)
package net.cogindo.ssl;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
@sguzman
sguzman / scala-fibonacci-stream.scala
Last active May 27, 2016 21:53
Fibonacci Stream
val fib: Stream[BigInt] = BigInt(0) #:: BigInt(1) #:: fib.zip(fib.tail).map (n => n._1 + n._2)
@sguzman
sguzman / build.sbt
Created January 14, 2017 11:46
A good starting point for any SBT project. Got it from my Scalebra project.
/** Name of project */
name := "Scalebra"
/** Project Version */
version := "1.0"
/** Scala version */
scalaVersion := "2.11.8"
/** Scalac parameters */
@sguzman
sguzman / build.sbt
Last active January 19, 2017 07:17
Better build.sbt starting point
/** Name of project */
name := "ScowerBot"
/** Organization */
organization := "initialcommit.io"
/** Project Version */
version := "1.0"
/** Do not download deps every time */
@sguzman
sguzman / proxy-rest-server.go
Created March 1, 2017 03:15
A server that is used for doing JSONP REST requests.
package main
import (
"fmt"
"net/http"
"strings"
"net/url"
"io/ioutil"
"log"
)
@sguzman
sguzman / proxy-rest-server-caching.go
Created March 2, 2017 01:26
A proxy RESTful server with caching
package main
import (
"fmt"
"net/http"
"strings"
"net/url"
"io/ioutil"
"log"
)