Skip to content

Instantly share code, notes, and snippets.

@lengocgiang
lengocgiang / textviewautolayout.swift
Last active May 31, 2020 06:14
UITextView height with AutoLayout( SnapKit)
// I'm using snapkit
// You can add to viewDidLoad
let address = UITextView(frame: CGRectZero)
address.text = restaurant.address
let sizeThatFits = address.sizeThatFits(CGSize(width: view.frame.width, height: CGFloat(MAXFLOAT)))
mainView.addSubview(address)
address.snp_makeConstraints { (make) -> Void in
let superview = mainView
make.top.equalTo(superview.snp_top)
make.left.equalTo(superview.snp_left)
@lengocgiang
lengocgiang / STDINCompileC.sublime-build
Last active March 25, 2016 09:24
Console input with terminal
{
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"],
"selector" : "source.c",
"shell" : false,
"working_dir" : "$file_path"
}
// C programming
#include <stdio.h>
#define IN 1
#define OUT 0
int main(int argc, char const *argv[])
{
int c, i, nwhite, nother;
#define RGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define HEXCOLOR(c) [UIColor colorWithRed:((float)((c & 0xFF0000) >> 16))/255.0 green:((float)((c & 0xFF00) >> 8))/255.0 blue:((float)(c & 0xFF))/255.0 alpha:1.0]
#define UIColorFromRGB(rgbValue) \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 \
alpha:1.0]
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
// find depth key in NSDictionary
- (id)findKey:(NSString *)keyname inObject:(id)object {
for (id subKey in object) {
id subObject = [object objectForKey:subKey];
if ([subKey isEqualToString:keyname]) {
return subObject;
#if Debug
#define DLog(...) NSLog(@"%@(%d),%@),__PRETTY_FUNCTION__,__LINE_,[NSString stringWithFormat:__VA_ARGS__])
#elif Release
#define DLog(...)
#endif
validateName(name: String) {
if (name) {
if (/^[A-Za-z0-9][a-z0-9._\-]*$/.exec(name)) {
return true;
}
}
return false;
}
validateEmail(email: String) {
@lengocgiang
lengocgiang / go_ultilities.go
Last active May 16, 2017 07:55
I wrote a few mini functions to convert and support with go lang
package main
import (
"fmt"
"reflect"
)
func main() {
checkType()
}
@lengocgiang
lengocgiang / helper
Created May 26, 2017 02:42
[MacOSX]How to fix "configure: error: pcre.h not found
I'm using MacOSX Siera 10.12
sudo ln -s /usr/local/Cellar/pcre/8.40/include/pcre.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/pcre.h
If you do not install "pcre" , you can using brew
brew install pcre
package main
import (
"errors"
"database/sql"
"encoding/json"
"fmt"
_ "github.com/go-sql-driver/mysql"
)