Skip to content

Instantly share code, notes, and snippets.

View BranLiang's full-sized avatar
🏠
Working from home

bran BranLiang

🏠
Working from home
View GitHub Profile
@BranLiang
BranLiang / qiniu.ts
Last active March 6, 2019 12:59
[File Uploaders] qiniu, qcloud #upload
import qiniu, { rs } from "qiniu";
import { File, ResourceTypes } from "@utils/interfaces";
import sanitize from 'sanitize-filename';
import uuidv4 from 'uuid/v4';
const mac = new qiniu.auth.digest.Mac(
process.env.QINIU_ACCESS_KEY,
process.env.QINIU_SECRET_KEY
);
@BranLiang
BranLiang / file.sh
Last active April 15, 2019 14:25
Shell helpers
# upload local folder to server
scp -r localfolder/path user@server:/remote/path
import { nanoid } from 'nanoid'
class Connection {
peerConnection
channel
constructor() {
this.identifier = nanoid()
this.localICECandidates = []
this.connected = false
@BranLiang
BranLiang / elliptic_curve_certificate
Created April 8, 2021 06:55
create a self-signed elliptic curve certificate using ruby-openssl
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'openssl'
private_ec = OpenSSL::PKey::EC.new('prime256v1')
private_ec.generate_key
puts "Your private key:"
puts private_ec.to_pem
@BranLiang
BranLiang / unix-network-configuration.md
Last active January 16, 2023 14:51
Unix network configuration

A tunnel interface example:

utun10: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1350 inet 10.10.0.6 --> 10.10.0.5 netmask 0xffffffff

The following parameters are specific to IP tunnel interfaces, gif(4):

tunnel src_addr dest_addr Configure the physical source and destination address for IP tunnel interfaces. The arguments src_addr and dest_addr are interpreted as the outer source/destination for the encapsulating IPv4/IPv6 header.

@BranLiang
BranLiang / gist:e816bcda14c6c5c6098b9a60475c519d
Created June 29, 2024 04:45
Toggle IP address configuration between DHCP and Manual
function toggle_dhcp() {
router_address="192.168.1.105"
# Get the list of all network services
network_services=$(networksetup -listallnetworkservices | tail -n +2)
# Function to get the IP address of a network service
get_ip_address() {
networksetup -getinfo "$1" | grep "IP address: 192.168" | awk '{print $3}'
}
@BranLiang
BranLiang / controller_test_login_as.rb
Last active October 19, 2024 01:33
Rails 8 authentication setup for controller test
# test/test_helper.rb
def login
post session_url, params: { email_address: users(:one).email_address, password: "password" }
end
# test/controllers/campaigns_controller_test.rb
class CampaignsControllerTest < ActionDispatch::IntegrationTest
setup do
@BranLiang
BranLiang / system_test_login_as.rb
Created October 19, 2024 01:31
Rails 8 basic authentication setup for system test
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ]
def login_as(user)
visit new_session_url
fill_in "email_address", with: user.email_address
fill_in "password", with: "password"
click_on "Sign in"