Skip to content

Instantly share code, notes, and snippets.

@popcornylu
popcornylu / gist:1071312
Created July 8, 2011 07:31
[ios] Copy sqlite db from main bundle
NSString* docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* dbPath = [docPath stringByAppendingPathComponent:@"mydatabase.db"];
NSFileManager *fm = [NSFileManager defaultManager];
// Check if the database is existed.
if(![fm fileExistsAtPath:dbPath])
{
// If database is not existed, copy from the database template in the bundle
NSString* dbTemplatePath = [[NSBundle mainBundle] pathForResource:@"mydatabase" ofType:@"db"];
NSError* error = nil;
@popcornylu
popcornylu / NSInvocation+PopcornyLu.h
Created October 28, 2011 09:43
NSInvocation addition to create instance by target, selector, and arguments
#import <Foundation/Foundation.h>
@interface NSInvocation (PopcornyLu)
+ (NSInvocation*) invocationWithTarget:(id)target
selector:(SEL)selector;
+ (NSInvocation*) invocationWithTarget:(id)target
selector:(SEL)selector
arguments:(id)firstArg, ... NS_REQUIRES_NIL_TERMINATION;
@end
@popcornylu
popcornylu / NSString+template.c
Created December 23, 2011 07:59
A very simple template engine for iOS
#import "NSString+template.h"
@implementation NSString (template)
+(NSString*)stringWithTemplate:(NSString*)template
fromMap:(NSDictionary*)map
{
NSString* retStr = nil;
NSMutableString* buffer = [NSMutableString new];
NSScanner* scanner = [[NSScanner alloc] initWithString:template];
#Referecne:
# 1. https://gist.github.com/zenorocha/7159780
# 2.
#install xcode command tool
xcode-select --install
# check
@popcornylu
popcornylu / Iterables.java
Created June 4, 2016 16:16
Iterable transformation
import java.util.function.Function;
public class Iterables {
public static <F, T> Iterable<T> map(
Iterable<F> iterable,
Function<F, T> mapper)
{
return null;
}
}
@popcornylu
popcornylu / SQL_Join_Quiz.md
Last active June 4, 2016 16:40
SQL Join Quiz

Questions

來考一下SQL知識

Q1

如果兩個Table,size分別是m跟n,m>0 請問inner join的話最多會產生多少record?

  1. max(m, n)
  2. min(m, n)
  3. m + n
@popcornylu
popcornylu / ThrottlingInvoker.java
Last active June 8, 2016 04:05
Throttle the number of concurrent tasks in a thread pool.
import java.util.LinkedList;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
public class ThrottlingInvoker{
@popcornylu
popcornylu / kubectl-mvpvc
Created August 24, 2019 10:17
Rename or migrate a PVC from one namespace to another
#!/bin/bash
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo "Usage: kubectl-mvpvc <ns1/pvc1> <ns2/pvc2>"
exit 1
fi
NS_PVC_FROM=$1
NS_PVC_TO=$2
@popcornylu
popcornylu / CLI.md
Last active July 18, 2023 08:05
sc-31723: Comparison summary

The new added output is mark as +

$ piperider compare
...
 [  OK  ]   orders.customer_id                                not_null_orders_customer_id
 [  OK  ]   orders.gift_card_amount                           not_null_orders_gift_card_amount
 [  OK  ]   orders.order_id                                   not_null_orders_order_id
 [  OK  ]   orders.order_id                                   unique_orders_order_id