Skip to content

Instantly share code, notes, and snippets.

object Main extends App{
val weights = Seq(10, 5, 1)
println(Seq("000", "001", "010", "011", "100", "101", "110", "111").permutations.toStream
.foldLeft[(Int, Seq[Seq[String]])]((0, Seq.empty)) { (prev, set) =>
val count = set.tail.foldLeft((0, set.head)) { (acm, elem) =>
(acm._1 + acm._2.zip(elem).zipWithIndex.foldLeft(0) { (sum, e) =>
sum + (if (e._1._1 != e._1._2) weights(e._2) else 0)
}, elem)
}._1
if (count > prev._1) {
@yonezawaizumi
yonezawaizumi / StringHelper.scala
Last active December 14, 2018 13:33
Scalaでキャメルケースをスネークケースに変換する ref: https://qiita.com/yonezawaizumi/items/b7156102ea6fa1230abd
object StringHelper {
private val separatees = "[a-z](?=[A-Z])|[0-9](?=[a-zA-Z])|[A-Z](?=[A-Z][a-z])|[a-zA-Z](?=[0-9])".r
def camel2Snake(s: String): String = separatees.replaceAllIn(s, _.group(0) + '_')
.toLowerCase
}
var config = require('config');
var cluster = require('cluster');
function exec(module, index) {
console.log((new Date()).getTime() + '[' + index + ']: ' + require('./' + config.cron.modulePath + '/' + module).hoge);
}
function execs(modules, id, exitOnFinish) {
console.log('execute ' + id + ' begin');
var config = require('config');
var fs = require('fs');
fs.readdir(config.cron.modulePath, function (err, files) {
if (err) {
console.error(err);
} else {
files.forEach(function(file) {
console.log(require('./' + config.cron.modulePath + '/' + file.substr(0, file.length - 3)).hoge);
})
@yonezawaizumi
yonezawaizumi / ViewController.swift
Last active January 25, 2017 15:29
画像をダブルタップとピンチイン・ピンチアウトで拡大・縮小する Swift3編 ref: http://qiita.com/yonezawaizumi/items/bd3f53b2f4d80f815357
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet var myImageView: UIImageView!
@IBOutlet var myScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
self.myScrollView.delegate = self
@yonezawaizumi
yonezawaizumi / AppDelegate.h
Created January 3, 2017 09:30
iOSのプッシュ通知と位置情報の利用許諾がかぶるのを抑止する ref: http://qiita.com/yonezawaizumi/items/16464e8747f8d4799dff
@protocol LocationUpdatedDelegate
- (void)beginLocating:(BOOL)enabled;
- (void)locationWasUpdated:(CLLocationCoordinate2D)location;
@end
@interface AppDelegate : UIResponder<UIApplicationDelegate, CLLocationManagerDelegate>
@property(nonatomic) id<LocationUpdatedDelegate> locationDelegate;
@yonezawaizumi
yonezawaizumi / AppDelegate.m
Last active January 9, 2017 03:54
Firebaseプッシュ通知をObjective-Cで実装してみた ref: http://qiita.com/yonezawaizumi/items/fc9c37b08ad889304ff1
@interface AppDelegate ()
// お知らせ表示用のナビゲーションコントローラー
@property(nonatomic, strong) UINavigationController *informationNavigationController;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {