Skip to content

Instantly share code, notes, and snippets.

View masahitojp's full-sized avatar
🎯
Focusing

Masato Nakamura masahitojp

🎯
Focusing
View GitHub Profile
@thomaslee
thomaslee / connection.rs
Created January 17, 2014 07:34
A crappy, unbounded, half-baked, broken connection pool in Rust
use std::clone::Clone;
use std::option::{Option, None, Some};
use std::io::net::ip::{SocketAddr, IpAddr};
use std::io::net::tcp::TcpStream;
use std::io::net::addrinfo::get_host_addresses;
use std::rc::Rc;
pub struct Connection {
addr: SocketAddr,
conn: Rc<TcpStream>
@dirkraft
dirkraft / build.gradle
Last active June 23, 2017 15:00
A build.gradle project template, which bootstraps all necessary parts of a Java, Maven, IntelliJ project on GitHub with the minimum artifact publishing requirements to Sonatype's Maven central.
/* Root build.gradle for Java, Maven, and IntelliJ with Maven central POM. Assumes GitHub.
You should eventually read through and understand this entire Gradle script. Last tried with IntelliJ 2017.1.
Quick start:
- Copy this file into a directory named for your project.
- Choose one Gradle integration mode. Once chosen, stick to it.
IntelliJ Gradle integration:
- Import the project directory as a Gradle project.
- To change Gradle files, enable auto-synchronize or click the synchronize button in the Gradle panel.
@essen
essen / my_module.erl
Created October 14, 2013 03:25
Thinking in Erlang: The Code
-module(my_module).
-export([my_function/1, my_function/2]).
-export([infinite_loop/0, f/1, r/2, sort/1]).
-export([only_primes/1, is_prime/1]).
my_function(A) when is_integer(A) ->
my_function(A, 0);
my_function(A) when is_list(A) ->
my_function(list_to_integer(A), 0).
@sevastos
sevastos / aws-multipartUpload.js
Last active October 8, 2023 10:43
Example AWS S3 Multipart Upload with aws-sdk for Node.js - Retries to upload failing parts
// Based on Glacier's example: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/examples.html#Amazon_Glacier__Multi-part_Upload
var fs = require('fs');
var AWS = require('aws-sdk');
AWS.config.loadFromPath('./aws-config.json');
var s3 = new AWS.S3();
// File
var fileName = '5.pdf';
var filePath = './' + fileName;
var fileKey = fileName;
@knzm
knzm / gist:5185369
Last active December 30, 2020 14:34

Python パッケージングのこれまでとこれから

第1世代: distutils

$ python setup.py build
@kmizu
kmizu / UseEither.scala
Created September 6, 2012 12:04
Avoid nested pattern match with Either
object UseEither {
def doSomething(arg: String): Either[Throwable, Option[String]] = arg match {
case "none" => Right(None)
case "some" => Right(Some("some"))
case _ => Left(new Exception("example exception"))
}
def main(args: Array[String]) {
val somethingEither = for {
s <- doSomething(args(0)).right
@almost
almost / glacier.py
Created August 21, 2012 17:59
Amazon Glacier from Python. There's now a branch for this, see here: https://github.com/almost/boto/tree/glacier
# Thomas Parslow http://almostobsolete.net
# Just a work in progress and adapted to what I need right now.
# It does uploads (via a file-like object that you write to) and
# I've started on downloads. Needs the development version of Boto from Github.
#
# Example:
#
# glacierconn = GlacierConnection(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY)
# writer = GlacierWriter(glacierconn, GLACIER_VAULT)
# writer.write(somedata)
@udzura
udzura / fgcs.git.sh
Last active October 7, 2015 10:17
Fxcking git cheet sheet
# stage の操作
git add . # stage に加える
git add -p # stage にインタラクティブに加える
git add -N . # stage にファイルだけ加える
git rm hoge/hoge.rb # stage から消す
git rm -f hoge/hoge.rb # stage から無理矢理消す、先にファイルを消してしまった場合
git mv hoge/hoge.rb hoge/hoge2.rb # ファイル名変える
# 差とか状態を確認する系
git diff # HEADとunstagedの差分を確認する
@xuwei-k
xuwei-k / not_tailrec.scala
Created June 26, 2012 16:32 — forked from j5ik2o/gist:2996293
リトライハンドラーの殴り書き
object RetryUtil {
case class RetryException(throwables: List[Throwable]) extends Exception
def retry[T](retryLimit: Int, retryInterval: Int, shouldCatch: Throwable => Boolean)(f: => T): T = {
// @annotation.tailrec
def _retry( errors: List[Throwable], f: => T):T = {
try {
f
} catch {
@taichi
taichi / log.md
Last active December 15, 2021 02:12
ログ、その時の為に。