Skip to content

Instantly share code, notes, and snippets.

View andrewhao's full-sized avatar

Andrew Hao andrewhao

View GitHub Profile
@jweir
jweir / App.elm
Last active March 11, 2023 14:05
Work around for Elm Reactor programWithFlags (elm 0.18)
module App exposing (..)
import Html
type alias Flags =
{ name : String }
type alias Model =
@sasa1977
sasa1977 / xmerl_demo.ex
Last active July 26, 2023 10:07
Simple xmerl usage demo in Elixir
defmodule XmlNode do
require Record
Record.defrecord :xmlAttribute, Record.extract(:xmlAttribute, from_lib: "xmerl/include/xmerl.hrl")
Record.defrecord :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
def from_string(xml_string, options \\ [quiet: true]) do
{doc, []} =
xml_string
|> :binary.bin_to_list
|> :xmerl_scan.string(options)
@wxmn
wxmn / redis_helper.rb
Created March 31, 2011 13:23
How to Build a Fast News Feed in Redis and Rails
module RedisHelper
# decode Redis value back to Ruby object
def self.decode(json)
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"])
end
# encode Ruby object for Redis
def encoded
self.updated_at = nil
self.to_json