Skip to content

Instantly share code, notes, and snippets.

@hieuk09
hieuk09 / users.rb
Created Nov 28, 2020
ROM auto_struct does not respect struct configuration
View users.rb
require 'rom'
require 'rom-repository'
rom = ROM.container(:sql, 'sqlite::memory') do |conf|
conf.default.create_table(:users) do
primary_key :id
column :name, String, null: false
end
class Users < ROM::Relation[:sql]
View note-nes.md

Display

  • PPU has 3x cycle speed compare to CPU
  • PPU can render upto 64 sprite
  • Sprite could be 8x16 or 8x8
  • Color is specified by 2 bit in the pattern table, and 2 bit in the attribute table

Instruction set

  • Instruction set is based on addressing mode
  • The opcode is a 4 byte number
@hieuk09
hieuk09 / nes.md
Last active Mar 1, 2017
Note on NES specification
View nes.md

Note on NES specification

Introduction

NES is Nintendo Entertainment System, a gaming console which is popular in 1980s

Hardware Overview

Since I'm reading the specification while implementing the emulator for Chip8, there will be some comparison between them.

View acceptance_no_let_spec.rb
describe "validations" do
it "validates presence of github_username" do
acceptance = build(:acceptance, github_username: "")
expect(acceptance).to be_invalid
expect(acceptance.errors[:github_username]).to eq(["can't be blank"])
end
it "bubbles up user validations" do
acceptance = build(:acceptance, password: "")
@hieuk09
hieuk09 / runner.sh
Last active Aug 29, 2015
Runner for json serializer benchmark
View runner.sh
#!/bin/bash
array=("master" "acts_as_api" "active_model_serializers" "jbuilder" "jbuilder_with_partial" "rabl" "roar")
for i in "${array[@]}"
do
env -i git checkout $i
rspec
done
@hieuk09
hieuk09 / gist:09d485626911bdfd7c79
Created Apr 19, 2015
Download with progress bar
View gist:09d485626911bdfd7c79
require 'open-uri'
require 'fileutils'
require 'ruby-progressbar'
progress_bar = ProgressBar.create(
starting_at: 0,
total: nil,
format: "%a %B %p%% %r KB/sec",
rate_scale: lambda { |rate| rate / 1024 }
)
View something.rake
namespace :something do
task execute_patch: :environment do
# OtherClass is used in MyClass
OtherClass.class_eval do
def foo
'bar'
end
end
loop do
@hieuk09
hieuk09 / polymorphic_sample.rb
Last active Aug 29, 2015
Polymorphic sample
View polymorphic_sample.rb
class Animal
def name
'animal'
end
end
class Cow < Animal
def name
'cow'
end
View gist:8143930

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+ insert line after
@hieuk09
hieuk09 / gist:6745070
Created Sep 28, 2013
Auto unfriend facebook
View gist:6745070
// ==UserScript==
// @name Unfriend In Single-Click on Facebook by Cha
// @description This script is useful if you don't want to delete each friends one by one.
// @namespace Cha
// @include *.facebook.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js
// @version 3.6.1
// ==/UserScript==
// Developed by Cha(Muhammad Rafizan) - http://fb.com/cha.dae.woong.sunbae