Skip to content

Instantly share code, notes, and snippets.

@aphexmunky
aphexmunky / CharsetConversion.java
Created February 11, 2013 12:50
Converting to a specific charset
private String toSingleByteISO8859(String unicode) {
if (unicode != null) {
try {
ByteBuffer encoded = ISO_8859_1.encode(unicode);
String convertedString = new String(encoded.array(), ISO_8859_1.displayName());
return convertedString;
} catch (UnsupportedEncodingException e) {
logger.error("Problems converting to ISO-8859-1", e);
return "?";
}
@aphexmunky
aphexmunky / main.css
Created February 27, 2013 09:38
media selected css with sprite bg url
@media screen and (min-width: 1020px) {
#content:before {
content: " ";
background: url("/assets/images/layout/content-shadow@2x.png") 0 -542px no-repeat, url("/assets/images/layout/content-shadow@2x.png") right 0 no-repeat;
position: absolute;
top: 0;
left: -23px;
right: -23px;
display: block;
height: 540px;
@aphexmunky
aphexmunky / PreparedStatement.java
Created February 28, 2013 11:05
Spring PreparedStatement with GeneratedKeyHolder
public int insertManifestLine(final Integer shipmentNumber, final String countryCode,
final String organisationName, final String addressLine1, final String addressLine2,
final String town, final String county, final String postcode, final String title,
final String initials, final String name, final String telephoneNumber, final String email,
final String trackingNumber, final String orderNumber ) {
GeneratedKeyHolder key = new GeneratedKeyHolder();
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
@Override
@aphexmunky
aphexmunky / basic.css
Created March 1, 2013 02:28
Dreamweaver fluid layout basic
@charset "utf-8";
/* Simple fluid media
Note: Fluid media requires that you remove the media's height and width attributes from the HTML
http://www.alistapart.com/articles/fluid-images/
*/
img, object, embed, video {
max-width: 100%;
}
/* IE 6 does not support max-width so default to width 100% */
.ie6 img {
@aphexmunky
aphexmunky / timer.scala
Created March 1, 2013 02:35
Scala functional timer wrapper
object Timer {
def timer(t: => Any) = {
val start = System.currentTimeMillis
val func = t
val end = System.currentTimeMillis
println("function took " + (end - start) + " milliseconds")
}
}
@aphexmunky
aphexmunky / CronExample.scala
Created March 3, 2013 23:39
Taken from stackoverflow example - not my code
import akka.actor.Actor
import akka.actor.Actor._
import akka.camel.CamelServiceManager._
import akka.camel.Consumer
object CronExample {
def main(args: Array[String]) {
val cronExpressions: List[String] = ... // cron expressions read from database
#!/usr/bin/env python
import base64, hashlib, hmac, json, sys, getpass
from Crypto.Cipher import AES
from Crypto.Hash import RIPEMD, SHA256
base58_chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def prompt(p):
return getpass.getpass(p + ": ")
@aphexmunky
aphexmunky / SpringApp.scala
Created May 23, 2013 08:48
Quick snippet of using spring in scala app
object SpringApp extends App {
val ctx = new AnnotationConfigApplicationContext
ctx.scan(/* FIXME: update to correct value */"base.namespace")
ctx.refresh()
val system = ctx.getBean(classOf[ActorSystem])
}
@aphexmunky
aphexmunky / ReCaptcha.scala
Created July 16, 2013 11:00
Scala with Spring Autowired constructors
trait ReCaptchaVerifier {
def validate(reCaptchaRequest: ReCaptchaSecured): Boolean
}
@Service
class HttpClientReCaptchaVerifier @Autowired()(
httpClient: HttpClient,
servletRequest: HttpServletRequest,
@Value("${recaptcha_url}") recaptchaUrl: String,
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import akka.actor.{ActorSystem, Actor, Props, PoisonPill}
import akka.routing.BroadcastRouter
object Clicker extends App {
val system = ActorSystem("clicker")
main