Skip to content

Instantly share code, notes, and snippets.

View perforb's full-sized avatar

Yusuke Maeda perforb

View GitHub Profile
@perforb
perforb / div.pl
Created February 27, 2012 15:49
It sprits a character string in N characters.
#!/usr/bin/env perl
use 5.12.0;
use warnings;
# It sprits a character string in N characters.
my @alphabets = join('', 'a' .. 'y') =~ m/.{1,3}/g;
say join ',', @alphabets;
# >> abc,def,ghi,jkl,mno,pqr,stu,vwx,y
@perforb
perforb / blackjack.pl
Created February 29, 2012 17:26
Console game
#!/usr/bin/env perl
use 5.12.0;
use warnings;
use List::Util qw/shuffle/;
use constant {
P => 'Player',
D => 'Dealer',
};
@perforb
perforb / gist:2719493
Created May 17, 2012 14:59
Concatenate elisp files in the current directory
# Concatenate elisp files in the current directory
for f in $(ls | grep -E 'el$'); do $(cat $f >> concat.el); $(echo -e "\n" >> concat.el); done
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use constant LENGTH => 10;
my ($n, $min, $max) = (shift @ARGV || 8, 0, 0);
my @positions = ();
push @positions, int(rand(LENGTH + 1)) for (1 .. $n);
for my $position (@positions) {
@perforb
perforb / classic.sh
Created August 16, 2012 13:10
Comparison of `find`
find . -name "*.php" -exec rm -v {} \; | tee /dev/tty | wc -l
@perforb
perforb / main.cpp
Last active October 9, 2015 09:28
C++初心者が荷物運びゲームをつくってみた
/*
平山尚『ゲームプログラマになる前に覚えておきたい技術』より
お題:荷物運びゲームを2時間以内につくる
*/
#include<iostream>
using namespace std;
char screen[5][8] = {
@perforb
perforb / encapsulated.js
Last active October 12, 2015 00:57
Encapsulated object.
var obj = (function() {
var _canvas = 'canvas';
function _radian(x) {
return x * Math.PI / 180;
}
// public api
return {
canvas: _canvas,
radian: _radian
@perforb
perforb / Tweets Importer
Last active September 16, 2019 19:12
Tweets Importer - Imports your tweets to MySQL.
create database tweets_importer character set utf8;
create table user_timeline(
id int(10) auto_increment
,uid int(10) not null
,name varchar(255) not null
,text varchar(255) not null
,source varchar(255) not null
,retweet_count int(10) not null
,favorited int(1) not null
,retweeted int(1) not null
@perforb
perforb / unix_timestamp.js
Created January 8, 2013 16:36
Variation of current Unix timestamp.
// using static methods
console.log(Date.now()); // 1357662789317
// if you have Date objects
console.log(new Date().getTime()); // 1357662789317
// numeric context
console.log(+new Date); // 1357662789317
console.log(+new Date()); // 1357662789317
@perforb
perforb / history_cleaner.pl
Created January 26, 2013 13:24
.(BASH|ZSH)_HISTORY CLEANER - Delete duplicate rows as keeping the order.
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
my @lines;
while (<>) {
chomp;
next unless $_;
push @lines, $_;