Skip to content

Instantly share code, notes, and snippets.

@johnkchow
johnkchow / output.txt
Created February 13, 2019 02:27
ActiveSupport::Notifications will discontinue calling subscriber chain if any subscriber fails
irb(main):001:0> load '/private/var/folders/9q/0tnb0bwj5514jj4xl440f4j80000gn/T/sample.rb'
publish done
1
2
into 3
Traceback (most recent call last):
12: from /Users/johnkchow/.rbenv/versions/2.5.1/bin/irb:11:in `<main>'
11: from (irb):1
10: from (irb):1:in `load'
9: from /private/var/folders/9q/0tnb0bwj5514jj4xl440f4j80000gn/T/foo.rb:22:in `<top (required)>'
@johnkchow
johnkchow / 1_user.rb
Last active March 17, 2018 00:25 — forked from ericktai/1_user.rb
class User < ApplicationRecord
has_many :posts
has_many :comments
# id :integer not null, primary key
# name :string(50) default("")
end
# Service approach
class EmployeeService
def delete(employee_id)
employee = Employee.find(employee_id)
delete_reviews(employee)
disable_feedback_access(employee)
@johnkchow
johnkchow / action_base.rb
Created May 30, 2012 16:05
Simple action routing architecture w/ EM
# This is the base class for all Action processing classes. This is somewhat
# similar in concept to the Rails Controller/Action, and how the Rails router
# knows by convention what class/method to call.
class ActionBase
# Store all inherited classes.
def self.inherited(klass)
@actions ||= {}
@actions[klass.name] = klass
end
@johnkchow
johnkchow / em_tcp_message_framing.rb
Created February 21, 2012 21:46
Simple EventMachine TCP messaging framing example
require 'bindata'
module ServerConnection
def receive_data(data)
@buffer ||= []
@data_size ||= 0
@current_size ||= 0
if @buffer.empty?
# First four characters of any framed message will always be the size of message
@johnkchow
johnkchow / HtmlHelperExtension.cs
Created February 18, 2011 03:02
MvcScriptController - Compresses all script in a global js directory into one file HtmlHelperExtension - automatically generate <link> elements for css files depending on controller/action
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using System.IO;
using Core.Service;
namespace NestleGFGL.Extensions.Helpers
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex.GetType() != typeof(HttpException))
{
if (ex.GetType() == typeof(HttpUnhandledException) && ex.InnerException != null)
ex = ex.InnerException;
CoreManager.ExceptionService.HandleException(ex);
}
else if (ex.GetType() == typeof(HttpException))
private delegate void MyEventHandler();
private void DownloadUpdates(MyEventHandler OnUpdate, MyEventHandler OnFinish)
{
try
{
SetProgress(5);
MessageLabel.Do(ctl => ctl.Text = AvailableUpdate.DownloadingUpdateLabelText);
//software updates always take precedence over data updates
SetProgress(50);
asdfsadf
Console.WriteLine("whatttttup");