Skip to content

Instantly share code, notes, and snippets.

View ptwoms's full-sized avatar

Pyae Phyo Myint Soe ptwoms

View GitHub Profile
//To generate base64 encrypted text: https://jsfiddle.net/gCHAG/3036/
//Add #import <CommonCrypto/CommonCrypto.h> in *-Bridging-Header.h
extension String {
//TO DO: refactor later
func toHex() -> String {
var strToReturn = ""
var strIndex = self.startIndex
while strIndex < self.endIndex {
if let uScalar = UnicodeScalar(String(self[strIndex])) {
//: Playground - noun: a place where people can play
import UIKit
//sample board class
class Board{
var noOfCols, noOfRows: Int
var items: [[Character]]
init(rows: Int, cols: Int, board: [[Character]]) {
static void checkClassMethods(Class className);
void checkClassMethods(Class className){
Method *methods;
unsigned int nMethods;
methods = class_copyMethodList(className, &nMethods);
Method curMethod;
while (nMethods--) {
curMethod = methods[nMethods];
NSLog(@"method name %@", NSStringFromSelector(method_getName(curMethod)));
Dl_info info;
//can remove 'if' checks and excess code if u knows that the underlining implementation can handle those situation well :
static inline void checkClassAndMethodIntegrity(Class classToTest, SEL methodToTest, const char *pathName, const char *nearestObjectSymbol) __attribute__((always_inline));
void checkClassAndMethodIntegrity(Class classToTest, SEL methodToTest, const char *pathName, const char *nearestObjectSymbol) {
Dl_info info;
IMP imp = class_getMethodImplementation(classToTest, methodToTest);
if (imp && dladdr(imp, &info)) {
//printf("dli_fname: %s\n", info.dli_fname);
//printf("dli_sname: %s\n", info.dli_sname);
//printf("dli_fbase: %p\n", info.dli_fbase);
@inline(__always) func exitIfThereIsDebuggerAttached(){
#if !DEBUG
var size = strideof(kinfo_proc)
var info = kinfo_proc()
var name : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
memset(&info, 0, size)
let ret = sysctl(&name, 4, &info, &size, nil, 0)
if ret != 0 || info.kp_proc.p_flag & P_TRACED != 0{//exit if sysctl is failed or P_TRACED is set
//do additional steps here
+ (NSString *)getFormatForNumber:(CGFloat)floatNumber{
NSString *floatNumberStr = [NSString stringWithFormat:@"%.7f", floatNumber];
NSString *defaultFormat = @"#,##0.00";
NSString *currentFormat = defaultFormat;
NSRange fromDecimalRange = [floatNumberStr rangeOfString:@"."];
if (fromDecimalRange.location != NSNotFound) {
NSRange fromFormatRange =[floatNumberStr rangeOfString:@"[1-9]" options:NSRegularExpressionSearch];
if (fromFormatRange.location != NSNotFound && fromFormatRange.location >= fromDecimalRange.location+2) {
NSMutableString *firstFormat = [NSMutableString stringWithString:defaultFormat];
//
// P2MSUserAgentHelper.m
//
// Created by PYAE PHYO MYINT SOE on 20/11/14.
// Copyright (c) 2015 P2MS. All rights reserved.
//
#import "P2MSUserAgentHelper.h"//add method declaration here
#import <sys/utsname.h>
#import <net/if.h>
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
/**
* Created by pyaephyoms on 27/1/15.
*/
public class AndroidUserAgentHelper {
private static String userAgentString = null;
package com.locale.library.localehelper;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import java.util.Locale;
/**
* Created by pyae phyo myint soe on 9/1/15.