Skip to content

Instantly share code, notes, and snippets.

@fuxingloh
fuxingloh / FakeNavigationBar.swift
Last active March 29, 2019 04:54
Add fake navigation bar, remove, revert, load, unload and change status tint color, fake navigation bar can be used to assist transition from a controller with navigation background to one without.
extension UIViewController {
// Nav tag id
private var fakeNavTag: Int{get{return 80327}}
// Remove bar bar color and add fake nav bar
public func loadFakeNavigationBar(){
removeNavigationBarBackground()
addFakeNavigationBar()
}
@fuxingloh
fuxingloh / PushDissolveAnimationSegue.swift
Last active March 29, 2019 04:51
iOS Swift: A PushDissolveAnimationSegue with a dissolve animation,
class PushDissolveAnimationSegue: UIStoryboardSegue {
override func perform() {
let transition = CATransition()
transition.duration = 0.2
transition.type = kCATransitionFade
self.sourceViewController.navigationController!.view.layer.addAnimation(transition, forKey: kCATransition)
self.sourceViewController.navigationController!.pushViewController(self.destinationViewController, animated: false)
@fuxingloh
fuxingloh / Double.swift
Created November 15, 2015 06:32
Swift: round down double to x decimal places
extension Double {
/// Rounds the double to decimal places value
func roundToPlaces(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return round(self * divisor) / divisor
}
}
@fuxingloh
fuxingloh / ButtonGroup.swift
Last active November 15, 2015 06:34
iOS Swift: Group buttons together?
class ButtonGroup{
let buttons: [UIButton]
let defaultBackgroundColor: UIColor?
let defaultTitleColor: UIColor?
let unSelectable: Bool
let activeBackgroundColor: UIColor
let activeTitleColor: UIColor
@fuxingloh
fuxingloh / Awareness.swift
Created November 15, 2015 06:36
iOS Swift: Location Awareness, do task when location data is provided.
//
// Awareness.swift
// Edible
//
// Created by Fuxing on 7/5/15.
// Copyright (c) 2015 3Lines. All rights reserved.
//
import Foundation
import CoreLocation
@fuxingloh
fuxingloh / DynamoDBCount.java
Created November 19, 2015 08:35
DynamoDB count total rows that match key and filter expression also fixes the reserved word issues
Table table = dynamoDB.getTable(UserActivity.Table.TableName);
Map<String, Object> valueMap = new HashMap<>();
valueMap.put(":user_id", getUserId());
valueMap.put(":state", UserActivity.STATE_ACTIVE);
valueMap.put(":type", type);
QuerySpec spec = new QuerySpec()
.withNameMap(new NameMap()
.with("#s", "State").with("#t", "Type"))
@fuxingloh
fuxingloh / shell.sh
Created April 23, 2016 14:44
SeLinux Nginx Proxy Pass
# Check Status
sestatus
# Turn it on with -P flag
setsebool -P httpd_can_network_connect on
# Reboot Server to apply change
sudo reboot
@fuxingloh
fuxingloh / docker-rebuild.sh
Created April 27, 2016 17:27
Docker Rebuild with stop, rm, rmi build and run
#!/usr/bin/env bash
# Use it like this ./docker-rebuild.sh name 80:80
#chmod +x rebuild.sh
#./rebuild.sh
NAME=$1
PORT=$2
# Clean and Remove all
@fuxingloh
fuxingloh / app.js
Last active February 24, 2023 16:16
How to use express.js and passport.js with G Suite SAML Apps SSO
const express = require('express')
const SamlStrategy = require('passport-saml').Strategy
const passport = require('passport')
const cookieSession = require('cookie-session')
const cookieParser = require('cookie-parser')
// Create express instance
const app = express()
@fuxingloh
fuxingloh / PatternSplit.java
Last active January 14, 2020 06:10
Java regex string splitter that keeps the delimiter. Java string split with delimiter kept.
public class PatternSplit {
private final Pattern pattern;
/**
* @param pattern pattern for the splitter
*/
private PatternSplit(Pattern pattern) {
this.pattern = pattern;
}