Skip to content

Instantly share code, notes, and snippets.

@ayush
ayush / PrettyTimeParser.scala
Created September 26, 2015 03:03
Parse a string "1 year, 2 months, 5 minutes" into DateTime
object PrettyTimeParser {
private val YEAR_REGEX = """(?<YEAR>\d+)\s*years?""".r
private val MONTH_REGEX = """(?<MONTH>\d+)\s*months?""".r
private val WEEK_REGEX = """(?<WEEK>\d+)\s*weeks?""".r
private val DAY_REGEX = """(?<DAY>\d+)\s*days?""".r
private val HOUR_REGEX = """(?<HOUR>\d+)\s*hours?""".r
private val MINUTE_REGEX = """(?<MINUTE>\d+)\s*minutes?""".r
private def lookup(regex: scala.util.matching.Regex, s: String): Int = {
Try(regex.findAllIn(s).toList.headOption.map(_.split(" ")).map(_(0).toInt)).getOrElse(None).getOrElse(0)
@ayush
ayush / places
Created June 24, 2015 04:54
Places mentioned in I spent the last 15 years trying to become an American and failed
https://news.ycombinator.com/item?id=9764564
US 108
Canada 42
America 42
U.S. 25
Zealand 20
Europe 18
NZ 17
Japan 16
# Install cucumber & protractor
echo \\nInstalling Components...
npm install -g cucumber protractor
# Download and install selenium webdrivers
echo \\nInstalling selenium webdrivers...
webdriver-manager update
# TODO: Run Server
@ayush
ayush / monmem
Last active August 29, 2015 13:57
shows key memory stats and open files/sockets for a system + process
while true; do
date; echo;
ps aux | awk '{print $2, $4, $11}' | sort -k2r | head -n 5; echo;
free -m; echo;
cat /proc/meminfo | egrep '(Slab|SRec|SUnr)'; echo;
cat /proc/$(pidof $1)/status | grep Vm;
echo; echo '_____________________'; echo;
cat /proc/sys/fs/file-nr; echo;
sudo lsof -c $1 | wc -l; echo;
sudo lsof -i -c $1 | grep CLOSE_WAIT | wc -l; echo;
# source:
# http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/proc.txt#n800
#
# MemTotal: Total usable ram (i.e. physical ram minus a few reserved
# bits and the kernel binary code)
# MemFree: The sum of LowFree+HighFree
# MemAvailable: An estimate of how much memory is available for starting new
# applications, without swapping. Calculated from MemFree,
# SReclaimable, the size of the file LRU lists, and the low
# watermarks in each zone.
$ free -g
total used free shared buffers cached
Mem: 7 4 2 0 0 2
-/+ buffers/cache: 1 5
Swap: 0 0 0
$ free -m
total used free shared buffers cached
Mem: 7454 4450 3004 0 168 2695
-/+ buffers/cache: 1586 5868
@ayush
ayush / google-webfonts-categories.json
Created November 16, 2012 10:02
Google Webfonts Category Mapping
{
"Handwriting": [
"Calligraffitti",
"Coming Soon",
"Crafty Girls",
"Homemade Apple",
"Just Another Hand",
"Montez",
"Permanent Marker",
"Rancho",
@ayush
ayush / FontsList.scala
Created November 16, 2012 09:33
Google Webfonts List
object FontsList {
val fonts = Array(
"./apache/aclonica/METADATA.json",
"./apache/calligraffitti/METADATA.json",
"./apache/cherrycreamsoda/METADATA.json",
"./apache/chewy/METADATA.json",
"./apache/comingsoon/METADATA.json",
"./apache/craftygirls/METADATA.json",
"./apache/creepstercaps/METADATA.json",
"./apache/crushed/METADATA.json",
@ayush
ayush / Main.as
Created August 28, 2012 15:45
Main.as
package
{
import com.wordnik.api.batch.*;
import com.wordnik.api.client.*;
import com.wordnik.api.entity.*;
import com.wordnik.api.entity.word.*;
import com.wordnik.api.event.*;
import flash.display.Sprite;
import flash.text.TextField;
@ayush
ayush / Play.scala
Created April 20, 2012 11:56
Play 2.0 Json <-> Object Binding/Marshalling/Unmarshalling
// taken from http://www.playframework.org/documentation/api/2.0/scala/play/api/libs/json/package.html
case class User(id: Long, name: String, friends: List[User])
implicit object UserFormat extends Format[User] {
def reads(json: JsValue): User = User(
(json \ "id").as[Long],
(json \ "name").as[String],
(json \ "friends").asOpt[List[User]].getOrElse(List()))
def writes(u: User): JsValue = JsObject(List(