Skip to content

Instantly share code, notes, and snippets.

@implementation AutoRotatingWindow
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotate:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
}
return self;
<html>
<head>
</head>
<body>
<script type="text/javascript">
navigator.os = (function() {
var ua = navigator.userAgent, tem,
M= ua.match(/.*\((.+?);.*?([012356789_\.]+).*?\).*/i) || [];
return M[1];
@meiwin
meiwin / merge_sort.go
Created May 9, 2014 13:46
non-recursive merge sort in go
package main
import (
"fmt"
"math/rand"
"time"
)
func sort(data []int, pleft, pleft_end, pright, pright_end int) {
@meiwin
meiwin / gist:4193601
Created December 3, 2012 08:18
Secure Credentials
import java.io._
import java.security._
import org.apache.commons.codec.binary.Base64
object SecureCredentials {
def isValidPassword(password: String, hashedPassword: String, passKey: String) = {
try {
val theHashedPassword = hash(password, passKey)
@meiwin
meiwin / Serializers.scala
Created November 12, 2012 07:26
fasterxml/jerkson custom json serializers
import java.sql.{Timestamp, Date}
import org.codehaus.jackson.map._
import org.codehaus.jackson.{Version, JsonGenerator, JsonParser}
import java.util.TimeZone
import java.text.SimpleDateFormat
import com.codahale.jerkson.Json
import org.codehaus.jackson.map.module.SimpleModule
import org.codehaus.jackson.map.annotate.JsonSerialize
object CustomJson extends Json {
@meiwin
meiwin / gist:4043998
Created November 9, 2012 06:07
Jerkson custom serializer/deserializer
import com.codahale.jerkson.Json
import org.codehaus.jackson.map.module.SimpleModule
import org.codehaus.jackson.{JsonParser, JsonGenerator, Version}
import org.codehaus.jackson.map.annotate.JsonCachable
import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer, SerializerProvider, JsonSerializer}
object CustomJson extends Json {
val module = new SimpleModule("CustomJson", Version.unknownVersion())
// --- (SERIALIZERS) ---
module.addSerializer(classOf[Enumeration#Value], new JerksonEnumerationSerializer())
@meiwin
meiwin / AppConfig.scala
Created October 31, 2012 17:03
App Config #Play2 #Scala
package utils
import com.twitter.querulous.query.SqlQueryFactory
import com.twitter.querulous.evaluator.StandardQueryEvaluatorFactory
import com.twitter.querulous.database.ApachePoolingDatabaseFactory
import com.twitter.util.Duration
import java.util.concurrent.TimeUnit
import play.api.Play.current
import play.api.Play.configuration
@meiwin
meiwin / gist:3944779
Created October 24, 2012 08:18
Lift JSON Scala serializer for Enumeration
import net.liftweb.json.JsonAST.{JObject, JField, JString, JValue}
import net.liftweb.json._
import net.liftweb.json.JsonAST.JField
import net.liftweb.json.JsonAST.JObject
import net.liftweb.json.JsonAST.JString
import net.liftweb.json.TypeInfo
import net.liftweb.json.MappingException
class EnumerationSerializer[T <: Enumeration#Value](enum: Enumeration, clazz: Class[T]) extends Serializer[T] {
@meiwin
meiwin / gist:3034192
Created July 2, 2012 16:46
resizing view on keyboard apperance/disapperance
#pragma mark - Handle Keyboard Appearance/Disappearance
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGRect kbRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
kbRect = [self.view convertRect:kbRect toView:nil];
CGRect viewRect = [self.view convertRect:self.view.frame fromView:nil];
CGRect newRect = CGRectMake(viewRect.origin.x
,viewRect.origin.y
@meiwin
meiwin / gist:2914678
Created June 12, 2012 03:19
[java] Https connection system properties for connection to server with self-signed certificate
// keyStore (client cert)
System.setProperty("javax.net.ssl.keyStoreType" , "pkcs12"); // corresponds to `.keyStore`
System.setProperty("javax.net.ssl.keyStore" , "clientcert.p12");
System.setProperty("javax.net.ssl.keyStorePassword" , "password"); //
// trustStore (server cert)
System.setProperty("javax.net.ssl.trustStoreType" , "jks"); // corresponds to `.trustStore`
System.setProperty("javax.net.ssl.trustStore" , "servercert.keystore"); // path to server truststore, when the server cert is imported into
System.setProperty("javax.net.ssl.trustStorePassword", "password");
// The above code can be substituted with below parameters when starting the jvm