Skip to content

Instantly share code, notes, and snippets.

View cheeyeo's full-sized avatar
💭
Researching on use of transformers in computer vision

Chee Yeo cheeyeo

💭
Researching on use of transformers in computer vision
View GitHub Profile
@cheeyeo
cheeyeo / lets.ex
Created January 2, 2016 19:09 — forked from radarek/lets.ex
defmodule ExUnit.Lets do
defmacro __using__([]) do
quote do
import ExUnit.Lets
end
end
defmacro let(name, expr) do
if match?([do: _], expr) do
expr = expr[:do]
@cheeyeo
cheeyeo / README.md
Created January 2, 2016 19:07 — forked from radarek/README.md
@cheeyeo
cheeyeo / README.md
Created October 23, 2015 15:00 — forked from JoelQ/README.md
Using Shell Scripts for a Better User Experience (source for https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts)

Server scripts

This is the source for the scripts discussed in https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts

Both scripts are in the bin/ directory of the repo that contains all the markdown documents for blog posts. Users run bin/server and everything is automatically set up for them to view a local preview of the blog. bin/server-setup is a dependency of bin/server and is never run directly by users.

Maitre-d is the name of the "blog engine" discussed in the article.

@cheeyeo
cheeyeo / optparse-template.rb
Created September 30, 2015 13:33 — forked from rtomayko/optparse-template.rb
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@cheeyeo
cheeyeo / csp.rb
Last active September 19, 2015 20:21
CSP
module GitHub
module CSP
# Public: Constants for CSP keywords
NONE = "'none'".freeze
SELF = "'self'".freeze
UNSAFE_INLINE = "'unsafe-inline'".freeze
UNSAFE_EVAL = "'unsafe-eval'".freeze
# Public: Constants for CSP directive names
BASE_URI = "base-uri".freeze
@cheeyeo
cheeyeo / Enhance.js
Last active September 15, 2015 11:56 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@cheeyeo
cheeyeo / importer.rb
Last active August 29, 2015 14:27 — forked from yellow5/importer.rb
Ruby spec stubbing a block using mocha
class Importer
def parse_csv_file(csv_file)
File.open(csv_file) do |file|
ActiveRecordModel.transaction do
import_csv_stream(file)
end
end
end
end
@cheeyeo
cheeyeo / transactions.markdown
Last active August 29, 2015 14:27 — forked from jcasimir/transactions.markdown
Transactions

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

@cheeyeo
cheeyeo / gist:7aa4a5cf0db050d6216d
Last active September 13, 2021 21:29 — forked from beanieboi/gist:ad526faf063181f336a2
Codeship Nginx Config for Heroku
daemon off;
# Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
events {
use epoll;
accept_mutex on;
worker_connections 1024;
}
@cheeyeo
cheeyeo / xml_parser.rb
Last active August 29, 2015 14:27 — forked from kmile/xml_parser.rb
A small nokogiri xml reader DSL.
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here: http://nokogiri.org/Nokogiri/XML/Reader.html
#
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
#
# A small example:
#