An implementation of http://www.google.com/design/spec/components/pickers.html in AngularJS and some bootstrap just for helper classes (just the button classes).
Work in progress.
| SELECT nspname || '.' || relname AS "relation", | |
| pg_size_pretty(pg_relation_size(C.oid)) AS "size" | |
| FROM pg_class C | |
| LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
| WHERE nspname NOT IN ('pg_catalog', 'information_schema') | |
| ORDER BY pg_relation_size(C.oid) DESC | |
| LIMIT 20; |
| @Singleton | |
| public class DBCP implements IDBCP { | |
| private final Sql2o sql2o; | |
| public DBCP() { | |
| String configPath = | |
| getClass().getClassLoader().getResource("").getPath() + "hikari.properties"; | |
| sql2o = | |
| new Sql2o(new HikariDataSource(new HikariConfig(filePath)), new PostgresQuirks()); |
| // http://stackoverflow.com/questions/20262036/slick-query-multiple-tables-databases-with-getting-column-names/20278761#20278761 | |
| import scala.slick.jdbc.{GetResult,PositionedResult} | |
| object ResultMap extends GetResult[Map[String,Any]] { | |
| def apply(pr: PositionedResult) = { | |
| val rs = pr.rs // <- jdbc result set | |
| val md = rs.getMetaData(); | |
| val res = (1 to pr.numColumns).map{ i=> md.getColumnName(i) -> rs.getObject(i) }.toMap | |
| pr.nextRow // <- use Slick's advance method to avoid endless loop | |
| res | |
| } |
| /* | |
| gcc -Wall -pedantic -std=c99 -O2 -o timegm timegm.c | |
| Test manual epoch calculation with tm_yday vs TZ+mktime. | |
| On Linux, gcc 4.4.7, the manual method is ~5x faster. | |
| Usage: | |
| ./timegm | |
| <ctrl-C> to quit |
| var arrowPolyline = L.Polyline.extend({ | |
| addArrows: function(){ | |
| var points = this.getLatLngs() | |
| for (var p = 0; p +1 < points.length; p++){ | |
| var diffLat = points[p+1]["lat"] - points[p]["lat"] | |
| var diffLng = points[p+1]["lng"] - points[p]["lng"] | |
| var center = [points[p]["lat"] + diffLat/2,points[p]["lng"] + diffLng/2] | |
| var angle = 360 - (Math.atan2(diffLat, diffLng)*57.295779513082) | |
| var arrowM = new L.marker(center,{ | |
| icon: new L.divIcon({ |
An implementation of http://www.google.com/design/spec/components/pickers.html in AngularJS and some bootstrap just for helper classes (just the button classes).
Work in progress.
| //Using simple bitwise operations: | |
| data[0] = (byte) (width & 0xFF); | |
| data[1] = (byte) ((width >> 8) & 0xFF); | |
| //How it works: | |
| /* | |
| & 0xFF masks all but the lowest eight bits. | |
| >> 8 discards the lowest 8 bits by moving all bits 8 places to the right. | |
| The cast to byte is necessary because these bitwise operations work on an int and return an int, which is a bigger data type than byte. The case is safe, since all non-zero bits will fit in the byte. For more information, see Conversions and Promotions. |
| public class Crc16 { | |
| public static void main(String... a) { | |
| byte[] bytes = new byte[] { (byte) 0x08, (byte) 0x68, (byte) 0x14, (byte) 0x93, (byte) 0x01, (byte) 0x00, | |
| (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x01, | |
| (byte) 0x00, (byte) 0x13, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x22, (byte) 0x09, | |
| (byte) 0x11 }; | |
| byte[] byteStr = new byte[4]; | |
| Integer crcRes = new Crc16().calculate_crc(bytes); | |
| System.out.println(Integer.toHexString(crcRes)); |
| ByteBuf buf = ... | |
| byte[] bytes = new byte[buf.readableBytes()]; | |
| buf.readBytes(bytes); | |
| //If you don't want the readerIndex to change: | |
| ByteBuf buf = ... | |
| byte[] bytes = new byte[buf.readableBytes()]; | |
| int readerIndex = buf.readerIndex(); | |
| buf.getBytes(readerIndex, bytes); |