Skip to content

Instantly share code, notes, and snippets.

@AtsushiSuzuki
AtsushiSuzuki / Gulpfile.js
Last active September 30, 2015 13:17
Gulpfile recipe for gulp-less with gulp.watch
var gulp = require('gulp');
var less = require('gulp-less');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var lesses = ['src/less/**/*.less'];
gulp.task('less', function () {
return gulp.src(lesses)
.pipe(sourcemaps.init())
.pipe(plumber())
@AtsushiSuzuki
AtsushiSuzuki / rx-async.js
Created October 2, 2015 03:36
Rxjsでasync.series相当の処理を行う。
const Rx = require('rx');
Rx.Observable.prototype.mapParallel = function (fn) {
return this.concatMap((v) => Rx.Observable.fromNodeCallback(fn)(v));
};
Rx.Observable.prototype.mapSeries = function (fn) {
return this.concatMap((v) => Rx.Observable.defer(() => Rx.Observable.fromNodeCallback(fn)(v)));
};
@AtsushiSuzuki
AtsushiSuzuki / Vagrantfile
Created October 21, 2015 13:51
VagrantでNode.js用ソースディレクトリをunionfs-fuseでマウントするテスト
Vagrant.configure(2) do |config|
config.vm.box = 'ubuntu/trusty64'
config.vm.provision 'shell', inline: <<-SCRIPT
curl -sL https://deb.nodesource.com/setup_4.x | bash
apt-get upgrade -y
apt-get install -y nodejs build-essential unionfs-fuse
SCRIPT
config.vm.provision 'shell', privileged: false, inline: <<-SCRIPT
mkdir ~/.src ~/src
unionfs-fuse -o cow ~/.src=RW:/vagrant=RO ~/src
@AtsushiSuzuki
AtsushiSuzuki / formatDate.php
Created December 1, 2015 08:52
PHPで和暦の計算
<?php
function formatDate($time, $format = 'Y年M月d日 H時m分s秒', $timezone = null) {
$cal = IntlCalendar::createInstance($timezone, 'ja_JP@calendar=japanese');
$fmt = IntlDateFormatter::create('ja_JP', null, null, null, $cal, $format);
return $fmt->format($time);
}
echo formatDate(time(), 'Gy年') . PHP_EOL;
// => 平成27年
@AtsushiSuzuki
AtsushiSuzuki / index.php
Created December 4, 2015 08:01
PHPフレームワークとWordpressを共存させる
<?php
require_once __DIR__ . '/vendor/autoload.php';
$app = new \Silex\Application();
$app->get('/hello', function () {
return 'Hello, world!';
});
$app->error(function ($ex) use ($app) {
@AtsushiSuzuki
AtsushiSuzuki / range.cc
Created December 19, 2015 00:29
C++でpythonのrange
#include <iostream>
#include <iterator>
template <typename T>
class IncreasingNumberIterator: public std::iterator<std::input_iterator_tag, T>
{
private:
T n_;
public:
IncreasingNumberIterator(T n): n_(n) {}
@AtsushiSuzuki
AtsushiSuzuki / MovingAverageFilter.ts
Created January 18, 2016 16:38
pixi.js用移動平均フィルタ
class MovingAverageFilter extends PIXI.AbstractFilter {
static fragmentSrc(size: number, width: number, height: number, direction: string) {
return `
precision lowp float;
varying vec2 vTextureCoord;
varying vec4 vColor;
uniform sampler2D uSampler;
void main(void)
{
gl_FragColor = vec4(0.0);
@AtsushiSuzuki
AtsushiSuzuki / MainWindow.xaml
Created May 18, 2016 11:30
ViewModel => Viewのイベント通知
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Hello!" Command="{Binding DoSomething}"/>
@AtsushiSuzuki
AtsushiSuzuki / queue.js
Last active August 5, 2016 16:14
ES2015 function queue
"use strict";
class Queue {
constructor() {
this.running = false;
this.items = [];
}
enqueue(fn) {
using System;
using System.Windows;
using System.Windows.Data;
namespace WpfApplication1
{
public class DependencyPropertyTracker : DependencyObject
{
public object Value
{