Skip to content

Instantly share code, notes, and snippets.

Avatar

Amos Lanka amoslanka

View GitHub Profile
@amoslanka
amoslanka / Text Substitutions.plist
Last active Dec 11, 2015
Text substitutions for emojis and other helpful shortcuts. Drag this onto your OSX text substitutions preferences pane.
View Text Substitutions.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>phrase</key>
<string>👎</string>
<key>shortcut</key>
<string>:-1:</string>
</dict>
View clear_rpush_feedback.rb
Rpush::Client::Redis::Apns::Feedback.all.each do |feedback|
if Device.exists?(feedback.device_token)
puts "Device exists: #{feedback.device_token}"
else
feedback.destroy
end
end
@amoslanka
amoslanka / sentinal.rb
Created Aug 3, 2015
Adjustment to Redis client's Seninel example in order to confirm that blocking operations are booted during a failover. (https://github.com/redis/redis-rb/blob/98e3e7a516fc9b4609bc8ab482605f835a4de621/examples/sentinel.rb)
View sentinal.rb
require 'redis'
# This example creates a master-slave setup with a sentinel, then connects to
# it and sends write commands in a loop.
#
# After 30 seconds, the master dies. You will be able to see how a new master
# is elected and things continue to work as if nothing happened.
#
# To run this example:
#
View cache_marks.md

Cache Marks

An introduction of the pattern of using cache “marks” for use in building cache keys and indicating resource state uniqueness.

A cache mark is a simple value that represents a unique state of a resource or group of resources as a whole or in a particular context. A commonly used (but not referred to as) cache mark is a resource’s updated_at timestamp. It is updated to the current time when a resource is updated allowing for cache keys that use that mark to automatically invalidate caches based on previous versions of that resource’s mark. In the case of a group of resources a mark may be used to invalidate keys whenever any member of the collection is modified or removed.

Cache marks must be stored separately from the resource itself when:

  • a lookup of that mark must be performed more quickly than, for example, a database query
  • the mark represents a context of the resource, such as in the context of an associated record
@amoslanka
amoslanka / service.rb
Created Dec 4, 2014
A stripped down version of interactors.
View service.rb
require "ostruct"
# A base Service Object module.
#
# Example usage:
#
# class DoSomething
# include Service
# def call
# puts context.foo
@amoslanka
amoslanka / 1.md
Last active Aug 29, 2015
JSON metadata examples
View 1.md

GET /syllabi/1 Using wrapper objects

{
  "type": "syllabus",
  "properties": {
    "id": 1,
    "title": "Build a Simple Website",
    "description": "Smells Like Bakin",
@amoslanka
amoslanka / api_version.rb
Created Aug 7, 2014
Rack middleware that extracts an API version from either path or accept header.
View api_version.rb
require 'rack'
module Rack
class ApiVersion
def initialize(app, options = {})
@app = app
@options = options
end
def call(env)
View gist:7420832
_.--~~~~~~~---------------._
,=-,.--#####----..--------. `.
,' ,/ _/_ #### :! ` ``.
, ,/ [.[.]-=## :! / ` `.`.
, ,/ /_ )# :! // // ` `.`.
, /7 |_/ # :! // / ` `.`. ___,-
. ; | \___/ :! ; `~`= /
___,--`--( ;_____/__ \____:!__________,-' `. /
__,--' '~~ \ \ __` ______ `.
_,-' _ ____\ \-o . /ZZZZZ/ `.
View gist:7016328
function Player(name, age, handicap, etc) {
this.name = name;
}
// VS.
function Player(name, age, handicap, etc) {
return {
name: name,
age: age,
@amoslanka
amoslanka / rsyslog.conf
Last active Jun 24, 2016
Configuration for rsyslog for Nginx and PHP only. Output to /var/log/loggly and send to Loggly as well.
View rsyslog.conf
#################
#### MODULES ####
#################
$ModLoad imuxsock # provides support for local system logging
$ModLoad imfile
###########################
#### GLOBAL DIRECTIVES ####
###########################
You can’t perform that action at this time.