Skip to content

Instantly share code, notes, and snippets.

@goooooouwa
goooooouwa / send-markdown-to-evernote.sh
Last active July 21, 2025 04:16
#evernote #markdowwn
for filename in ./_drafts/*.md; do
echo $filename
date=$(echo $filename | cut -c 11-20)
title=$(echo $filename | cut -c 22- | rev | cut -c 4- | rev)
geeknote create --title "$title" --created "$date" --content "$filename"
done
@goooooouwa
goooooouwa / import-card-diary-to-jekyll.js
Last active July 21, 2025 04:23
#jekyll #card-diary
var fs = require('fs');
const contents = fs.readFileSync('CardDiary-JSON.json', 'utf8');
const obj = JSON.parse(contents);
for (const d of obj.diaryExports) {
const diary = JSON.parse(d.content);
const date = d.createDate.substring(0, 10);
const filename = `${date}-${diary.title || 'log'}`;
var anim = this.node.getChildByName("flashLight").getComponent(cc.Animation);
// these 3 steps must in order to play and pause the animation at 0.5s
anim.setCurrentTime(0.5, 'flashLight');
anim.play("flashLight");
anim.pause('flashLight');
this.render().then(() => {
// these 2 steps must in order to resume the animation from 0.5s
anim.setCurrentTime(0.5, 'flashLight');
anim.resume("flashLight");
});
@goooooouwa
goooooouwa / node-orm-demo.js
Last active August 2, 2017 03:58
demo on how to use node.js orm to find all records and match text with LIKE. 关于如何使用node.js orm查询全部记录和LIKE文本匹配的demo。 https://github.com/dresende/node-orm2
// how to find all Person records
// 如何查找所有人的记录
Person.find() // or Person.all()
// how to find Person records with surname beginning with word "Gr"
// 如何查找surname以“Gr"字母开头的人的记录
Person.find({ surname: orm.like("Gr" + "%") })
@goooooouwa
goooooouwa / node_module.js
Last active July 21, 2025 04:25
nodejs basic module syntax #nodejs #module #javascript
// in module1.js
function a(){
console.log('hello');
}
module.exports.a = a;
// in module2.js
@goooooouwa
goooooouwa / pos v0.1.js
Created April 10, 2017 09:24
my code for pos v0.1
'use strict';
function printReceipt(inputs){
let purchaseSequence = getPurchaseSequence(inputs);
let itemGroups = groupItems(inputs);
let receiptView = buildReceiptString(itemGroups, purchaseSequence);
displayReceiptView(receiptView);
}
function getPurchaseSequence(items){
@goooooouwa
goooooouwa / code.md
Last active September 14, 2016 03:48
Manufactoria game code

naive sort

?lvl=27&code=c11:4f0;c12:4f0;c13:10f0;r11:7f1;c11:8f2;b11:9f2;b12:6f3;p12:7f0;c12:8f3;p12:9f3;c13:7f0;c13:9f2;r14:6f2;p14:7f1;c14:8f1;p14:9f2;b14:10f1;c15:6f2;b15:7f0;r15:9f3;c15:10f3;c16:6f3;c16:7f3;c16:8f3;c16:9f0;q12:10f0;c15:11f0;c14:11f0;c13:11f1;c11:5f2;c12:5f2;c13:5f2;c14:5f3;c11:6f1;c10:4f3;c10:5f3;c10:6f3;c10:7f3;g10:8f2;

bubble sort

?lvl=27&code=c9:7f1;c9:8f1;c9:9f1;c9:10f1;c9:11f1;b10:9f0;b10:10f0;r10:11f0;b11:9f0;p11:10f0;b11:11f0;c12:9f3;p12:10f3;r13:9f2;p13:10f2;b13:11f2;r14:9f2;r14:10f2;r14:11f2;c15:7f1;c15:8f1;c15:9f1;c15:10f1;c15:11f1;c10:7f3;c10:8f2;b11:7f3;c11:8f2;p12:7f3;c12:8f3;r13:7f3;c13:8f0;c10:6f3;c9:6f1;c15:6f1;g12:4f2;c13:4f3;c14:4f0;c15:4f0;c15:5f1;c13:5f0;q11:5f0;c12:5f0;c11:4f3;c10:4f2;c9:4f2;c9:5f1;g11:6f2;c12:6f3;c10:5f3;

rspec-rails doesn't require 'rspec-core' intensionally.

So without the 'rspec' command, 'rspec-core' is not required anywhere.

When using RSpec with Cucumber (which doesn't invoke the 'rspec' command'), we need to add 'rspec-expectations' and 'rspec-core' in Gemfile, so that bundler will auto-require them into Rails environment.

Why add a gem in Gemfile if it's already dependented by another gem? Being dependented only get it being installed, but not required. It's the depending gem's responsiblity to require the depedented gem. In this case, though 'rspec-rails' depends on 'rspec-core', it doesn't require 'rspec-core' in code (as explained above). So we need to add them to Gemfile, or require them explicitly somewhere in the codebase.

So if If you want to use rspec-core, you need to add it to your Gemfile. Cucumber will automatically load rspec-core's methods to be available in your step definitions. https://github.com/cucumber/cucumber/wiki/RSpec-Expectations

@goooooouwa
goooooouwa / redux.js
Last active July 21, 2025 04:25
#redux
new_state = root_reducer(old_state, action);
@goooooouwa
goooooouwa / key-based cache expiration.md
Last active April 2, 2016 11:25
a draft implementation of key-based cache expiration model proposed in DHH's article "How key-based cache expiration works" https://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works

Implementation

  1. implement a #cache_key method for every model, as this:
def cache_key
  "#{self.class.model_name.cache_key}/#{id}-#{self[:updated_at].utc.to_s(:number)}"
end
  1. update update_at field whenever the model or it's related models (through method such as touch) are changed.