Skip to content

Instantly share code, notes, and snippets.

View between40and2's full-sized avatar

Juguang XIAO between40and2

  • London & Beijing
View GitHub Profile
let bear = Array("bear")
let bird = Array("bird")
let diff = bird.difference(from: bear)
let newBird = bear.applying(diff)
print(diff)
print(newBird)
@between40and2
between40and2 / 21-new-in-foundation.swift
Created November 16, 2022 11:54
WWDC 2021 What's New in Foundation
func parsingDates() {
let date = Date.now
let format = Date.FormatStyle().year().day().month()
let formatted = date.formatted(format) // "Jun 7, 2021"
if let date = try? Date(formatted, strategy: format) {
// https://developer.apple.com/videos/play/wwdc2022/110357
import RegexBuilder
func ~=<T>(pattern :Regex<T> , value: String) -> Bool {
do {
return try pattern.firstMatch(in: value) != nil
} catch {
return false
}
@between40and2
between40and2 / rails-bin.md
Created July 1, 2014 01:15
Scripts under bin directory of your Rails app

bundle

#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

rails

@between40and2
between40and2 / -rails-routing-intro.md
Last active August 29, 2015 14:02
Rails Routing System components

input part

use part

##Methodology to examine routing system.

Playing with Rails console

$ rails c
> app.main_app.routes  

=> #

@between40and2
between40and2 / rails-http-basic-digest-auth.md
Created June 23, 2014 09:03
HTTP Basic/Digest Auth in Rails

ActionController::HttpAuthentication::Basic::ControllerMethods

  • authenticate_or_request_with_http_basic(realm = "Application", &login_procedure)
  • authenticate_with_http_basic(&login_procedure)
  • request_http_basic_authentication(realm = "Application")

ActionController::HttpAuthentication::Digest::ControllerMethods

@between40and2
between40and2 / rails-console.md
Last active August 29, 2015 14:02
Rails console tips

rails console

Model

> ActiveRecord::Base.connection.tables.map { |t| "#{t} => " + ActiveRecord::Base.connection.execute("select count(*) from #{t}").fetch_row.first}

@between40and2
between40and2 / rails-response.md
Last active August 29, 2015 14:02
This gist explains how to use render or redirect_to for HTTP response

render and redirect_to

To

@between40and2
between40and2 / form_for.md
Last active August 29, 2015 14:02
Comparing FormTagHelper, FormHelper, FormBuilder