Skip to content

Instantly share code, notes, and snippets.

View joyoyoyoyoyo's full-sized avatar
🏴
living it up and busy supporting my community.

Angel Ortega (he/they) joyoyoyoyoyo

🏴
living it up and busy supporting my community.
View GitHub Profile
@retronym
retronym / type-bounds.scala
Created December 16, 2009 11:17
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
@liquidz
liquidz / http.scala
Created March 3, 2010 11:02
OAuth Library for Scala
package com.uo.liquidz.http
import java.net.{URL, HttpURLConnection}
import java.io.{BufferedReader, InputStreamReader, BufferedWriter, OutputStreamWriter, IOException}
// ssl
import java.security.{KeyManagementException, NoSuchAlgorithmException, SecureRandom}
import java.security.cert.{CertificateException, X509Certificate}
import javax.net.ssl.{HttpsURLConnection, KeyManager, SSLContext, TrustManager, X509TrustManager}
import Simply._
# Identifying character names in The Adventures of David Simple
# source: http://www.munseys.com/diskone/davidsimp.htm
#
# commands:
# ./ner.sh david_simple.txt > david_simple.ner.txt
# sed -e 's/\S\+\/[^P]\w*//g' -e 's/\s\{2,\}/\n/g' -e 's/\/PERSON//g' david_simple.ner.txt | sort | uniq -c | sort -nr | sed 's/^\s\+//' | awk '{if ($1 > 1) print $1,"\t",substr($0, length($1)+2) }'
# note: ner.sh is Stanford NER http://nlp.stanford.edu/software/CRF-NER.html
238 David
131 Cynthia
@jsuereth
jsuereth / ExampleSocketServer.scala
Created May 14, 2011 02:14
IterateeNonBlockingEchoServer
package scalaz.example.nio
import scalaz._
import concurrent.Promise
import effects.IO
import nio.sockets._
import nio.Channels._
import Scalaz._
import iteratees._
import java.nio.channels.SocketChannel
@daltonhuynh
daltonhuynh / higher_order.scala
Created May 22, 2011 03:08
pattern matching in scala (map/fold)
// simple map and fold left/right implementations
// in scala using pattern matching for List[Int]
def map(list:List[Int], f:(Int) => Int):List[Int] = {
list match {
case Nil => Nil
case head::tail => f(head)::map(tail, f)
}
}
@jackywyz
jackywyz / continuations.scala
Created September 7, 2011 03:06
scala tips
// scala -P:continuations:enable
//Continuation对于诸如异步I/O,UI事件处理以及数据流并发之类的高级控制建造十分有帮助
import util.continuations._
object Continue{
def say =
reset {
shift {
cf:(Int=>Int) =>
val even = cf(10)
@mitchellh
mitchellh / gist:1277049
Created October 11, 2011 01:30
Configure Vagrant VM to use Host DNS for VPN
Vagrant::Config.run do |config|
# ...
config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
@takezoe
takezoe / JSONSample.scala
Created December 30, 2011 15:02
Example of scala.util.parsing.json
import scala.util.parsing.json._
val result = JSON.parseFull("""
{"name": "Naoki", "lang": ["Java", "Scala"]}
""")
result match {
case Some(e) => println(e) // => Map(name -> Naoki, lang -> List(Java, Scala))
case None => println("Failed.")
}
@umbrae
umbrae / genders.sql
Created January 17, 2012 19:00
Roughly detect gender by first name in SQL
-- This table is useful for rough statistics based on gender
-- Don't consider it scientific in any way.
--
-- Example use:
-- select COALESCE(
-- (SELECT gender
-- FROM gender_types
-- WHERE name=users.first_name
-- LIMIT 1),
-- 'U') gender_type, count(*)
@jasonrudolph
jasonrudolph / git-branches-by-commit-date.sh
Created February 12, 2012 20:40
List remote Git branches and the last commit date for each branch. Sort by most recent commit date.
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r