Skip to content

Instantly share code, notes, and snippets.

@lengocgiang
lengocgiang / time_format.go
Created August 28, 2018 11:14
format with string
package ivimage
import (
"fmt"
"testing"
"time"
)
func TestImage_Save(t *testing.T) {
// Please dont change value, you should change format
@lengocgiang
lengocgiang / animation.swift
Created December 3, 2017 09:52
addSubview and removeFromSuperview animation in Swift 4.0
# addSubview
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
self.view.addSubview(view)
}, completion: nil)
# removeFromSuperview
UIView.transition(with: self.view, duration: 0.25, options: [.transitionCrossDissolve], animations: {
subview.removeFromSuperview()
}, completion: nil)
@lengocgiang
lengocgiang / reflectcode.go
Created August 30, 2017 07:31
reflect code
// old
func getPreferredProductRefIdsFromContactProgress(contactProgress models.ContactProgress) []int {
if !contactProgress.IsEmpty() {
enterInfo := contactProgress.EnterInfo
enterInfoMap := make(map[string]interface{})
json.Unmarshal([]byte(enterInfo), &enterInfoMap)
if enterInfoMap["product_ref_ids"] != nil {
value := reflect.ValueOf(enterInfoMap["product_ref_ids"])
fmt.Println(value.Kind(), enterInfoMap["product_ref_ids"])
var rawData string
package main
import (
"errors"
"database/sql"
"encoding/json"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
@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
@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()
}
validateName(name: String) {
if (name) {
if (/^[A-Za-z0-9][a-z0-9._\-]*$/.exec(name)) {
return true;
}
}
return false;
}
validateEmail(email: String) {
#if Debug
#define DLog(...) NSLog(@"%@(%d),%@),__PRETTY_FUNCTION__,__LINE_,[NSString stringWithFormat:__VA_ARGS__])
#elif Release
#define DLog(...)
#endif
// 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;
#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)