Skip to content

Instantly share code, notes, and snippets.

View zaltoprofen's full-sized avatar

nakashima zaltoprofen

  • Tokyo, Japan
View GitHub Profile
#include <iostream>
#include <utility>
#include <tuple>
#include <typeinfo>
template<typename, template<typename...>class>
struct repack {
};
#include <iostream>
#include <utility>
template<template<typename ..._> class F, typename ...Ts>
F<Ts...> p(Ts... args){
return F<Ts...>(args...);
}
int main(int argc, char const* argv[])
{
private def request(charset: String)(f: => HttpUriRequest): Try[String] = Try {
val c = clientBuilder.build()
try {
val res = c.execute(f)
try {
EntityUtils.toString(res.getEntity, charset)
} finally {
HttpClientUtils.closeQuietly(res)
}
} finally {
import scala.annotation.tailrec
object Prog {
def primes(n: Int): List[Int] = {
@tailrec
def loop(cs: List[Int], ps: List[Int]): List[Int] = {
cs.headOption match {
case Some(n: Int) => loop(cs.tail.filterNot(_ % n == 0), n::ps)
case None => ps
}
import twitter4j._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object Main{
def open(url: String): Unit = {
import scala.sys.process.Process
Future { Process("open", Seq(url)).! }
}
@zaltoprofen
zaltoprofen / sushi.scala
Last active August 29, 2015 14:19
enumerate the urls of 🍣 and 🍜 from twitter.
import twitter4j._
object Main{
def main(args: Array[String]): Unit = {
val t = new TwitterStreamFactory().getInstance
t.addListener(new UserStreamAdapter {
override def onStatus(status: Status): Unit = {
val urls = status.getMediaEntities().collect { case e:MediaEntity if e.getType == "photo" => e.getMediaURL }
val eurls = status.getExtendedMediaEntities().collect { case e:ExtendedMediaEntity if e.getType == "photo" => e.getMediaURL }
(urls ++ eurls).distinct.foreach(println)
#!/bin/bash -x
for fname in $(find $1 -type f);do
mv $fname ${fname%:orig}
done
@zaltoprofen
zaltoprofen / DL twimg
Created February 28, 2015 10:19
download original size image from twimg
javascript:(function(){var e=window.location.href,t=new RegExp("(:(orig|large))?$");e=e.replace(t,":orig");var n=e.match(".+/(.+?):orig$")[1],o=document.createElement("a");o.href=e,o.setAttribute("download",n),o.dispatchEvent(new CustomEvent("click"))})();
#include <iostream>
#include <type_traits>
#include <iterator>
template<typename InputIterator, typename Predicate>
bool all_of(InputIterator begin, InputIterator end, Predicate pred){
static_assert(std::is_integral<typename std::result_of<Predicate(typename std::iterator_traits<InputIterator>::value_type)>::type>::value, "pred should return integral");
while (begin != end){
if(!pred(*begin++)) return false;
}
#include <iostream>
#include <type_traits>
#include <iterator>
#include <vector>
#include <utility>
template<typename Function, typename InputIterator>
auto mapping(Function f, InputIterator begin, InputIterator end)
-> std::vector<
typename std::result_of<Function(typename std::iterator_traits<InputIterator>::value_type)>::type