Skip to content

Instantly share code, notes, and snippets.

View saml's full-sized avatar

Sam Lee saml

  • New York, NY
View GitHub Profile
@saml
saml / sitemap_urls.py
Created February 19, 2013 19:01
extract <loc> urls from sitemap.xml
import sys
import os
import argparse
import gzip
import requests
try:
from lxml import etree
except ImportError:
@saml
saml / mongo_utils.js
Last active December 14, 2015 02:49
mongodb query builder
//query builder
var q = new (function() {
this.has = function(key, exists) {
if (typeof exists === 'undefined') {
//default, query for documents that has they key.
exists = true;
}
var query = {};
query[key] = {$exists: exists};
@saml
saml / inotify-jcr.bash
Created March 6, 2013 16:04
upload file to sling
#!/bin/bash
if (( $# < 2 ))
then
echo "Usage: <watchdir> <targethost:port/dir> [username:password]"
echo "example, $0 myapp localhost:8080/apps"
exit 1
fi
watchdir="$1"

Twitter公式クライアントのコンシューマキー

Twitter for iPhone

Consumer key: IQKbtAYlXLripLGPWd0HUA
Consumer secret: GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU

Twitter for Android

Consumer key: 3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPad

Consumer key: CjulERsDeqhhjSme66ECg

@saml
saml / menu_parse.pm
Created March 12, 2013 19:49
parse menu list to menu obj
use warnings;
use strict;
use Data::Dumper;
my $lines = [
"header1 dinner",
"header2 appetizer",
"item soup",
"item spring roll",
from django import forms
from django.db import models
class Menu(models.Model):
header = models.CharField(max_length=64)
price = models.DecimalField(null=True, max_digits=6, decimal_places=2)
parent = models.ForeignKey('Menu', null=True)
class MenuForm(forms.ModelForm):
class Meta:
@saml
saml / gist:5162549
Last active December 14, 2015 22:59
<qu1j0t3> hm, typesafe and others hiring http://functionaljobs.com/jobs/search/?q=scala
<saml> http://mandubian.com/2013/02/21/play-json-stand-alone/
<saml> wtf is that website i can't even highlight code snippet
<aloiscochard> saml: this is because it's volatile code
<qu1j0t3> aloiscochard: nothing a good heavy bucket can't fix
<aloiscochard> qu1j0t3: bucket-pasting is indeed the best approach here
<saml> play-json can't deserialize either
<saml> given model: https://github.com/saml/salat-trait-test/blob/master/src/main/scala/model/Model.scala can't deserialize simple json https://github.com/saml/salat-trait-test/blob/master/src/main/scala/app/SalatTraitTest.scala
<aloiscochard> this is not simple saml , there is polymorphism
<aloiscochard> saml: lift-json handle that
6583 15/Mar/2013:17:36:28 -0400 ~ 15/Mar/2013:17:36:35 -0400 GET /bin/services
object MongoDBUtils {
private def getAsRec[T: Manifest](dbo: MongoDBObject, keys: List[String]): Option[T] = keys match {
case Nil => None
case key :: Nil => dbo.getAs[T](key)
case key :: rest => dbo.getAs[DBObject](key).flatMap(doc => getAsRec[T](doc, rest))
}
def getAs[T:Manifest](dbo: MongoDBObject, key: String): Option[T] = getAsRec[T](dbo, key.split('.').toList)
}
case class MenuItemPortion(title: String, price: String)
object MenuItemPortion extends Convertable[MenuItemPortion] {
override def readFrom(dbo: MongoDBObject): Option[MenuItemPortion] = {
val title: Option[String] = dbo.getAs[String]("title")
val price: Option[String]= dbo.getAs[String]("price")
if (title.isEmpty && price.isEmpty) None
else Some(MenuItemPortion(title.getOrElse(""), price.getOrElse("")))
}
}