Skip to content

Instantly share code, notes, and snippets.

@hyone
hyone / gist:d6018ee1ac8f9496fed839f481eb59d6
Last active April 2, 2022 08:15
Practice: implement `Display` trait for `slice` wrapper
use std::fmt::{ Debug, Display, Formatter, Result };
use std::string::ToString;
#[derive(Debug)]
struct Slice<'a, T: 'a> {
data: &'a [T]
}
impl <'a, T: ToString> Display for Slice<'a, T> {
fn fmt(&self, f: &mut Formatter) -> Result {
@hyone
hyone / gist:1323137
Created October 28, 2011 19:04
evil-text-object-defun
(require 'evil)
(setq evil-move-defun-alist
'((ruby-mode . (ruby-beginning-of-defun . ruby-end-of-defun))
(c-mode . (c-beginning-of-defun . c-end-of-defun))
(js2-mode . (js2-beginning-of-defun . js2-end-of-defun))))
(defun evil-move-defun (count &optional begin-defun end-defun)
"Move by defun"
(let ((count (or count 1))
@hyone
hyone / gist:3950460
Created October 25, 2012 04:49
Multiple async HTTP requests by Haskell
{-# LANGUAGE FlexibleContexts #-}
import Data.Conduit
import qualified Data.Conduit.List as CL
import Network.HTTP.Conduit
import Control.Concurrent.Async (mapConcurrently)
import Control.Concurrent.MVar
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Control (MonadBaseControl)
@hyone
hyone / gist:1621163
Created January 16, 2012 14:39
Parallel download images from a picture site
;; (defproject parallel-download "1.0.0-SNAPSHOT"
;; :description "FIXME: write description"
;; :dependencies [[org.clojure/clojure "1.3.0"]
;; [clj-http "0.2.7"]
;; [enlive "1.0.0-SNAPSHOT"]]
;; :dev-dependencies [[swank-clojure "1.3.4"]]
;; :main parallel-download.core)
(ns parallel-download.core
(:use [clojure.string :only (join split)]
@hyone
hyone / gist:1032985
Created June 18, 2011 10:47
4clojure #53 - Longest continuous increasing subsequence
;; hyone's solution to Longest Increasing Sub-Seq
;; https://4clojure.com/problem/53
(fn longest-inc-seq [coll]
(reduce #(let [len-a (count %1)
len-b (count %2)]
(if (and (> len-b 1) (> len-b len-a)) %2 %1))
[]
(reductions
(fn [xs y]
[package]
name = "http_request1"
version = "0.1.0"
[dependencies]
hyper = "*"
@hyone
hyone / Cargo.toml
Created July 2, 2017 11:11
Rust で並列HTTP Request (非同期IO版) ref: http://qiita.com/hyone/items/7f448c46611d9b19e643
[package]
name = "http_request2"
version = "0.1.0"
[dependencies]
futures = "*"
hyper = "0.11.0"
tokio-core = "*"
@hyone
hyone / gitfile1.rs
Last active October 15, 2016 07:18
open file with std::error::Error
use std::error::Error as StdError;
use std::env;
use std::fmt;
use std::fs::File;
use std::io::Error as ioError;
use std::io::prelude::*;
use std::path::Path;
macro_rules! eprintln {
@hyone
hyone / gist:02b81a2a176ca0ada59a3343b6787b79
Last active October 9, 2016 07:53
Practice: lifetime qualifier added version of sample code at http://rustbyexample.com/trait.html
struct Sheep<'a> { naked: bool, name: &'a str }
trait Animal<'a> {
fn new(name: &'a str) -> Self;
fn name(&self) -> &str;
fn noise(&self) -> &str;
fn talk(&self) {
println!("{} says {}", self.name(), self.noise());
@hyone
hyone / file0.txt
Created April 7, 2016 10:46
Ecto.Query を SQL に変換する ref: http://qiita.com/hyone/items/06fd744c54d701617a7d
# iex -S mix
iex(1)> import Ecto.Query
nil
iex(2)> import Ecto.Adapters.SQL
nil
iex(3)> user_id = 2
2
iex(4)> q = from u in SampleApp.User, join: fu in assoc(u, :relationships), where: u.id == ^user_id, select: fu.id