Skip to content

Instantly share code, notes, and snippets.

View builtinnya's full-sized avatar

Naoto Yokoyama builtinnya

View GitHub Profile
@builtinnya
builtinnya / README.md
Last active September 20, 2018 09:10
For explanation purpose on DefinitelyTyped/DefinitelyTyped#28890
@builtinnya
builtinnya / s3_copy_attachments.rb
Created August 25, 2015 12:24
Paperclip S3 copy attachments
### S3 implementation of Paperclip module that supports deep
### cloning of objects by copying image attachments.
###
### Tested with: aws-sdk (1.33.0)
###
### Refer to Paperclip issue: https://github.com/thoughtbot/paperclip/issues/1361#issuecomment-39684643
### Original gist works with fog: https://gist.github.com/stereoscott/10011887
### gist works from which this code is derived: https://gist.github.com/ksin/7747334d60b1947f14e9
module Paperclip
@builtinnya
builtinnya / flavor.rb
Last active August 29, 2015 13:56 — forked from ttscoff/flavor.rb
#!/usr/bin/ruby
# Convert a Markdown README to HTML with Github Flavored Markdown
# Github and Pygments styles are included in the output
#
# Requirements: json gem (`gem install json`)
#
# Input: STDIN or filename
# Output: STDOUT
# Arguments: "-c" to copy to clipboard (or "| pbcopy"), or "> filename.html" to output to a file
# cat README.md | flavor > README.html
@builtinnya
builtinnya / add-onetime-hook.el
Created March 13, 2013 10:36
Onetime version of `add-hook'.
;; `lexical-binding' must be non-nil
(defun add-onetime-hook (hook function &optional append local)
"Add to the value of HOOK the function FUNCTION for onetime use.
HOOK should be a symbol, and FUNCTION may be any valid function.
See `add-hook'."
(labels ((wrapper ()
(funcall function)
(remove-hook hook #'wrapper)))
(add-hook hook #'wrapper append local)))
@builtinnya
builtinnya / permutations.js
Created March 12, 2013 15:31
A straightforward way to calculate permutations.
function permutations(arr) {
var result = [];
function remove(arr, index) {
return arr.filter(function(_, i) {
return index !== i;
});
}
function rec(arr, acc) {
@builtinnya
builtinnya / cue-programming-challenge.py
Created March 4, 2013 10:16
A trivial code for The Cue Programming Challenge.
# A trivial code for The Cue Programming Challenge
# URL: http://challenge.cueup.com/
# Level 1: The Longest Substring That Is The Same In Reverse
def filter_candidates(src_text):
"""Pick all the candidate substrings from the text."""
candidates = []
for i in range(len(src_text)):
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Mojolicious::Lite;
use OAuth::Lite::Consumer;
use OAuth::Lite::Token;
use JSON;
@builtinnya
builtinnya / colossal-cue-adventure.py
Last active November 12, 2021 08:17
A trivial code for solving the Colossal Cue Adventure.
# A trivial code for solving the Colossal Cue Adventure
# URL: http://adventure.cueup.com/
# Level 1: The VAX's MTH$RANDOM % 36 Roulette
def vax_rng_next(x):
"""Generate the next pseudo-random number."""
a, c, m = 69069, 1, 2**32
return (a * x + c) % m