Skip to content

Instantly share code, notes, and snippets.

View katopz's full-sized avatar
🦀
Rust me if you can

Todsaporn Banjerdkit katopz

🦀
Rust me if you can
View GitHub Profile
@katopz
katopz / google_translate_web_mobile.mm
Last active December 19, 2015 17:49
Will open google translate website for mobile and translate sent word to English
const NSString *_GOOGLE_URI = @"http://translate.google.com/m/translate?hl=en&sl=auto&tl=en&ie=UTF-8&prev=_m&q=";
-(void) openWebViewForGGranslate : (UIWebView*) webView translate: (NSString *) targetString
{
// clean up new line at end of string
targetString = [targetString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// escape URL encode
targetString = [targetString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
@katopz
katopz / HelloWordNet.mm
Created July 14, 2013 15:56
Will call WordNet for translate Thai to English via AFJSONRequestOperation as JSON
/*
// optional cache
// AFNetwork
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
*/
const NSString *_WORD_NET_URI = @"http://th.asianwordnet.org/services/dictionary/json/th2en/";
@katopz
katopz / UIColorFromRGBA
Created October 15, 2013 15:55
UIColorFromRGBA(0xA39B9FFF)
#define UIColorFromRGBA(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF000000) >> 24))/255.0 green:((float)((rgbValue & 0xFF0000) >> 16))/255.0 blue:((float)((rgbValue & 0xFF00) >> 8 ))/255.0 alpha:((float)((rgbValue & 0xFF))/255.0)]
@katopz
katopz / ane-draw-uiview-to-as3
Created March 1, 2014 17:37
Drawing iOS UIViews to AS3 bitmapData via Adobe AIR native extensions
// refer to : http://tyleregeto.com/article/drawing-ios-uiviews-to-as3-bitmapdata-via-air
Drawing iOS UIViews to AS3 bitmapData via Adobe AIR native extensions
2011.12.13
A major draw back to displaying native iOS UIView objects on top of your Adobe AIR applications is that they... well... are on top. Here is a quick code snippet for rendering native iOS view objects to ActionScript bitmapData objects via the recently released native extensions support. This allows you to add them to the display list (at the loss of all their native functionality). With native extensions we can update the bitmapData directly in memory which results in very fast updates. The possibilities are endless.
FREObject drawToBitmap(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
// grab the AS3 bitmapData object for writing to
@katopz
katopz / ane-worker-constructor-error
Created March 30, 2014 14:41
Allocate ANE with Worker in constructor will throw error e.g. ReferenceError: Error #1065: Variable com.freshplanet.ane.AirAlert::AirAlert is not defined.
package
{
import com.freshplanet.ane.AirAlert.AirAlert;
import flash.display.Sprite;
import flash.events.Event;
import flash.system.MessageChannel;
import flash.system.Worker;
import flash.system.WorkerDomain;
import flash.utils.setInterval;
@katopz
katopz / UIImage+Lazy.m
Created April 4, 2014 16:45
Using 16 bits instead of 32 bits cuts memory usage in half : http://www.dwellable.com/blog/Tech-iOS-Image-Tricks
@implementation UIImage (Dwellable)
- (UIImage *)crop:(CGRect)rect
{
return [self copyFromRect:rect toSize:rect.size];
}
- (UIImage *)copyToSize:(CGSize)dstSize
{
return [self copyFromRect:CGRectMake(0, 0, self.size.width, self.size.height)
_.mixin({templateFromUrl: function (url, data, settings) {
var templateHtml = "";
this.cache = this.cache || {};
if (this.cache[url]) {
templateHtml = this.cache[url];
} else {
$.ajax({
url: url,
method: "GET",
@katopz
katopz / crossbridge-flascc-obfuscation
Created August 3, 2014 16:46
Using CrossBridge/FlasCC for Code Obfuscation
// http://bruce-lab.blogspot.com/2014/08/using-crossbridgeflascc-for-code.html
// https://forums.adobe.com/message/5121420
// http://hecool108.blogspot.com/2013/08/hide-your-key-with-alchemyflascccrossbr.html
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "AS3/AS3.h"
void gk() __attribute__((used,
annotate("as3sig:public function ec(keystr:String):String"),
@katopz
katopz / fb-post-to-page-by-admin
Last active August 29, 2015 14:07
[FB] Post to page by admin
Post to page by admin
---
* user get access_token with manage_pages from app
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&display=touch&response_type=token&scope=manage_pages&redirect_uri=YOUR_REDIRECT_URI
* user get access_token from page id
https://graph.facebook.com/YOUR_PAGE_ID?fields=access_token&access_token=YOUR_ACCESS_TOKEN
* get log live access_token (2 months)
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=YOUR_ACCESS_TOKEN
@katopz
katopz / DBKUIColor
Created December 20, 2014 08:20
RGB Hex to UIColor
//
// DBKUIColor.swift
// DBKUIColor
//
// Created by Todsaporn Banjerdkit (katopz) on 12/19/14.
// Copyright (c) 2014 Debokeh. All rights reserved.
//
// Credit : http://stackoverflow.com/questions/24263007/how-to-use-hex-colour-values-in-swift-ios/24263296#24263296
import UIKit