Magic words:
psql -U postgresMost \d commands support additional param of __schema__.name__ and accept wildcards like *.*
\q: Quit/Exit\c __database__: Connect to a database\d __table__: Show table definition including triggers
| /** | |
| * Solves the n-Queen puzzle in O(n!) | |
| * Let p[r] be the column of the queen on the rth row (must be exactly 1 queen per row) | |
| * There also must be exactly 1 queen per column and hence p must be a permuation of (0 until i) | |
| * There must be n distinct (col + diag) and n distinct (col - diag) for each queen (else bishop attacks) | |
| * @return a Vector p of length n such that p[i] is the column of the queen on the ith row | |
| */ | |
| def nQueens(n: Int) = (0 until n).permutations filter {p => | |
| p.zipWithIndex.flatMap{case (c, d) => Seq(n + c + d, c - d)}.distinct.size == 2*n | |
| } |
Magic words:
psql -U postgresMost \d commands support additional param of __schema__.name__ and accept wildcards like *.*
\q: Quit/Exit\c __database__: Connect to a database\d __table__: Show table definition including triggers| #!/bin/bash | |
| #------------------------------------------------------------------------------ | |
| # Name: sbtmkdirs | |
| # Purpose: Create an SBT project directory structure with a few simple options. | |
| # Author: Alvin Alexander, http://alvinalexander.com | |
| # Info: http://alvinalexander.com/sbtmkdirs | |
| # License: Creative Commons Attribution-ShareAlike 2.5 Generic | |
| # http://creativecommons.org/licenses/by-sa/2.5/ | |
| #------------------------------------------------------------------------------ |
| # Bulk convert shapefiles to geojson using ogr2ogr | |
| # For more information, see http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/ | |
| # Note: Assumes you're in a folder with one or more zip files containing shape files | |
| # and Outputs as geojson with the crs:84 SRS (for use on GitHub or elsewhere) | |
| #geojson conversion | |
| function shp2geojson() { | |
| ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp" | |
| } |
| package operator | |
| object FunctionalPipeline { | |
| class PipedObject[T] private[Functional] (value:T) | |
| { | |
| def |>[R] (f : T => R) = f(this.value) | |
| } | |
| implicit def toPiped[T] (value:T) = new PipedObject[T](value) | |
| } |
| #Newbie programmer | |
| def factorial(x): | |
| if x == 0: | |
| return 1 | |
| else: | |
| return x * factorial(x - 1) | |
| print factorial(6) | |
| #First year programmer, studied Pascal |