This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- The first statement you need to run in your sql to setup migration. | |
| CREATE TABLE Versioning ( | |
| migrated VARCHAR(255) NOT NULL, | |
| appliedDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| PRIMARY KEY (migrated)); | |
| INSERT INTO Versioning (migrated) VALUES ('0.0.0.migration.sql'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Date Time Utils | |
| import java.text.DateFormat; | |
| import java.text.SimpleDateFormat; | |
| import java.time.*; | |
| import java.time.format.DateTimeFormatter; | |
| import java.util.Calendar; | |
| import java.util.Date; | |
| import java.util.Locale; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| default String connect(String url) throws IOException { | |
| try (CloseableHttpClient client = HttpClients.createDefault()){ | |
| // Create http post | |
| HttpGet get = new HttpGet(url); | |
| HttpResponse response = client.execute(get); | |
| return EntityUtils.toString(response.getEntity()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import co.threelines.puffin.util.GeoSpatialUtil; | |
| import com.spatial4j.core.shape.Point; | |
| import org.apache.commons.lang3.tuple.Pair; | |
| import java.util.Random; | |
| /** | |
| * Created by Fuxing | |
| * Date: 5/7/2015 | |
| * Time: 3:22 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo yum install java-1.8.0 | |
| sudo yum remove java-1.7.0-openjdk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ObjectMapper mapper = new ObjectMapper() | |
| // Via class | |
| Hey hey = mapper.readValue("{name:\"hey\"}", Hey.class); | |
| System.out.println(hey.name); | |
| // Via dynamic | |
| JsonNode node = mapper.readTree("{name:\"hey\"}"); | |
| // With null safety, allows chaining | |
| String name = node.path("name").asText(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.imageio.ImageIO; | |
| import javax.imageio.ImageReader; | |
| import javax.imageio.stream.ImageInputStream; | |
| import java.awt.*; | |
| import java.awt.image.BufferedImage; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.net.URL; | |
| import java.util.Iterator; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| // Camel case | |
| var camelCased: String { | |
| return self.characters.split{$0 == " "}.map(String.init).map{$0.capitalizedString}.joinWithSeparator(" ") | |
| } | |
| var capitalizeFirst:String { | |
| var result = self | |
| result.replaceRange(startIndex...startIndex, with: String(self[startIndex]).capitalizedString) | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func countLabelLines(label: UILabel) -> Int { | |
| // Call self.layoutIfNeeded() if your view uses auto layout | |
| let myText = label.text! as NSString | |
| let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude) | |
| let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil) | |
| return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class func blendColor(color1: UIColor, withColor color2: UIColor) -> UIColor { | |
| var r1:CGFloat = 0, g1:CGFloat = 0, b1:CGFloat = 0, a1:CGFloat = 0 | |
| var r2:CGFloat = 0, g2:CGFloat = 0, b2:CGFloat = 0, a2:CGFloat = 0 | |
| color1.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) | |
| color2.getRed(&r2, green: &g2, blue: &b2, alpha: &a2) | |
| return UIColor(red: max(r1, r2), green: max(g1, g2), blue: max(b1, b2), alpha: max(a1, a2)) | |
| } |
OlderNewer