Skip to content

Instantly share code, notes, and snippets.

View chunlea's full-sized avatar
👨‍💻
Working from home

chunli chunlea

👨‍💻
Working from home
View GitHub Profile
@chunlea
chunlea / apolloClient.ts
Created October 12, 2022 05:42
NextJS SSR with Apollo GraphQL Client, graphql-ruby and ActionCable
import {
ApolloClient,
from,
HttpLink,
InMemoryCache,
NormalizedCacheObject,
split,
} from '@apollo/client'
import { onError } from '@apollo/client/link/error'
import { concatPagination, getMainDefinition } from '@apollo/client/utilities'
@chunlea
chunlea / Dockerfile
Created January 26, 2022 21:08
Dockerfile for Rails with devcontainer support
# *****************************************************************************
# * Base image based on offical ruby alpine image with minimal dependencies. *
# *****************************************************************************
FROM ruby:3.1.0-alpine as base
RUN apk add --update --no-cache ca-certificates gcompat libpq tzdata
# *****************************************************************************
# * Builder image with all dependencies installed. *
# *****************************************************************************
@chunlea
chunlea / Gemfile
Created June 25, 2020 02:05 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@chunlea
chunlea / gist:41646d3a28181e5405d37dfc570ddb6b
Created January 31, 2019 16:07 — forked from mprymek/gist:8379066
Elixir metaprogramming example
# This is an example of metaprogramming in the Elixir language.
#
# We will define a domain specific language (DSL) for the definition
# of a service which is watched by several sensors.
# Each sensor watches some property/functionality of the service and
# returns the result of the check.
#
# To determine if the service is functioning properly, we need functions
# to run all the sensors' code and gather the returned data.
#
@chunlea
chunlea / Deploy-Rails-application-with-docker-swarm.md
Last active November 8, 2018 19:19
How to use docker swarm with docker machine to deploy your Rails application.
docker swarm init

# 创建管理环境
docker-machine create \
  --driver generic \
  --generic-ip-address=IP \
  --generic-ssh-key ~/.ssh/id_rsa \
  --swarm --swarm-master \
 taxigo
#!/usr/bin/sudo sh
## ruby_revealer.sh -- decrypt obfuscated GHE .rb files. 2.0.0 to 2.3.1+.
## From `strings ruby_concealer.so`:
##
## > This obfuscation is intended to discourage GitHub Enterprise customers
## > from making modifications to the VM.
##
## Well, good, as long as its not intended to discourage *me* from doing this!
@chunlea
chunlea / Deploy.cs
Created July 10, 2016 06:19 — forked from FrayxRulez/Deploy.cs
Deploy UWP apps to Windows 10 Mobile
// Initializes MultiTargetingConnectivity with current PC culture
var connectivity = new MultiTargetingConnectivity(Thread.CurrentThread.CurrentUICulture.LCID);
var devices = connectivity.GetConnectableDevices();
// Gets the first physical device attached to PC.
// WARNING: if more than a single device is connected to the PC deploy will fail.
var phone = devices.FirstOrDefault(x => !x.IsEmulator());
// PhoneProductId of the app, you can find it in your Package.appxmanifest
var package = Guid.Parse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");

Using Obj-C with MacRuby/Rubymotion

This little post aims to help you to translate Objective-C Blocks into Ruby blocks. Let's start by taking a look at few examples of iOS API call where blocks are used for animations and enumeration

Ruby Lambda Syntaxes:

Im Rubymotion and MacRuby you can use all the Ruby Lambda syntaxes that are:

block = lambda { |param|  ... }
@chunlea
chunlea / Locales.yaml
Last active August 29, 2015 14:10 — forked from wojtha/Locales.yaml
# config/locales/en.yml
en:
exception:
show:
not_found:
title: "Not Found"
description: "The page you were looking for does not exists."
internal_server_error:
title: "Internal Server Error"
@chunlea
chunlea / api.rb
Created November 26, 2014 03:55
If you want to use AFMotion with status code and errors, try this file.
class Api
class << self
# Init API server, with the shared client
def init_server
if Auth.needlogin?
AFMotion::SessionClient.build_shared(BASE_URL) do
session_configuration :default
header "Accept", "application/json"