Skip to content

Instantly share code, notes, and snippets.

@meiwin
meiwin / gist:1815541
Created February 13, 2012 09:49
CALayer animation (the correct way)
// sample codes for animating calayer's opacity
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithValue:0];
animation.toValue = [NSNumber numberWithValue:1];
targetLayer.opacity = 1; // must be set, otherwise targetLayer opacity will not be updated, even after animation is completed.
[targetLayer addAnimation:animation forKey:@"opacity"]; // the key "opacity" must match keyPath being animated.
@meiwin
meiwin / gist:1857364
Created February 18, 2012 04:17
Caching with GCD
// as seen in http://www.cocoanetics.com/2012/02/caching-caches/
// benefits: thread-safe
- (id) cachedObject
{
static dispatch_once_t onceToken;
static id objectToCache;
dispatch_once(&onceToken,^{
objectToCache = ...; // create the object
@meiwin
meiwin / gist:2292104
Created April 3, 2012 13:42
mig33 SQL (2)
-- Write a SQL query that will result in full table scan.
select *
from transaction_journal
where ucase(Receiver) = 'FOO'
-- Write a SQL query that can introduce a deadlock.
select *
from transaction_journal
for update
;
@meiwin
meiwin / gist:2292147
Created April 3, 2012 13:48
Mig33 SHELL
# Create a single line script that returns the number of httpd processes that are running on the current machine
ps -e | grep httpd | grep -cv grep
# From the current folder (/tmp), provide some bash commands that will rename all the *.txt files in mig33/inner/ to *.dat
for fn in ./mig33/inner_folder/*.txt; do mv "$fn" "${fn/.txt}.dat"; done
@meiwin
meiwin / gist:2292157
Created April 3, 2012 13:50
mig33 SQL (1)
-- Write a sql query that will return a list of duplicate phone numbers and the duplication count
select PhoneNumber, count(*) count
from TheTable
group by PhoneNumber
having count(*) > 1
;
-- Write a sql query that will return a list of IDs with duplicate phone numbers
select ID
from TheTable
@meiwin
meiwin / gist:2292190
Created April 3, 2012 13:54
mig33 Algorithm (1)
// Write java program that:
// takes its input from two files and prints out lines that exists in both files
package mig33;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
@meiwin
meiwin / gist:2292209
Created April 3, 2012 13:55
mig33 Algorithm (2)
/**
* In the language of your choice, write a function which, taking a positive integer n as input,
* finds all sets of numbers that sum up to n.
*
* For example, n=4, we have:
* 4
* 3,1
* 2,2
* 2,1,1
* 1,1,1,1
@meiwin
meiwin / gist:2701811
Created May 15, 2012 13:32
Responding to NSManagedObject lifecycle events with automatic callback to simple method naming convention.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// NSManagedObject+AutoUpdating.h
// Piggie
//
// Created by Meiwin Fu on 14/5/12.
@meiwin
meiwin / gist:2779731
Created May 24, 2012 06:00
Configure cxf wsdl2java to generate list setter in Maven
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>yourartifact</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<dependencies>
@meiwin
meiwin / gist:2914633
Created June 12, 2012 03:12
[java keytool] Import self-signed server certificate
keytool -import -alias <alias> -file <servercert.crt> -storepass <password> -keystore <keystore-file>