Skip to content

Instantly share code, notes, and snippets.

View RedFred7's full-sized avatar

Fred Heath RedFred7

View GitHub Profile
@dabit3
dabit3 / App.js
Last active November 16, 2022 05:46
Persisting a keypair for reading across clients
/*
* this file includes both a node.js script for creating a keypair
* as well as the client code for using it
*/
/* createKeypair.js */
const fs = require('fs')
const anchor = require("@project-serum/anchor");
const web3 = require('@solana/web3.js')
const account = anchor.web3.Keypair.generate();
@keithrbennett
keithrbennett / push-all
Last active July 30, 2018 08:36
Ruby script that pushes current branch to all remote repos in parallel.
#!/usr/bin/env ruby
#
# push_all Pushes commits and tags for the active branch to all remote repos.
#
BRANCH = `git rev-parse --abbrev-ref HEAD`.chomp
REMOTES = `git remote -v`.split("\n").map { |line| line.split.first}.sort.uniq
Result = Struct.new(:remote, :exit_code, :output)
#!/usr/bin/env ruby
require 'json'
USAGE = "USAGE:\ngit ticket TICKET_ID\n"
# get ticket ID from first command line argument
ticket_id = ARGV[0]
unless ticket_id
print USAGE
@iboard
iboard / fizz_buz.rb
Last active January 20, 2019 07:57
Benchmarking if versus map-matching (a kind of pattern-matching in ruby)
require "benchmark"
def log msg
# NOOP
end
def with_if(x)
x.times do |n|
if (n % 3 == 0) && (n % 5 != 0)
log 'Fizz'
@adam-p
adam-p / Local PR test and merge.md
Last active April 1, 2025 20:23
Testing a pull request, then merging locally; and avoiding TOCTOU

It's not immediately obvious how to pull down the code for a PR and test it locally. But it's pretty easy. (This assumes you have a remote for the main repo named upstream.)

Getting the PR code

  1. Make note of the PR number. For example, Rod's latest is PR #37: Psiphon-Labs/psiphon-tunnel-core#37

  2. Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

$ git fetch upstream pull/37/head:pr37
@damien-roche
damien-roche / rubymethodlookup.md
Last active October 4, 2024 18:23
A Primer on Ruby Method Lookup

A Primer on Ruby Method Lookup

Method lookup is a simple affair in most languages without multiple inheritance. You start from the receiver and move up the ancestors chain until you locate the method. Because Ruby allows you to mix in modules and extend singleton classes at runtime, this is an entirely different affair.

I will not build contrived code to exemplify the more complicated aspects of Ruby method lookup, as this will only serve to confuse the matter.

When you pass a message to an object, here is how Ruby finds what method to call:

1. Look within singleton class

  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
@Integralist
Integralist / Ruby Lambdas.md
Last active August 8, 2023 05:10
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@stuart11n
stuart11n / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@ChengLong
ChengLong / run_long_process_in_background.rb
Last active April 19, 2021 20:59
Run Background Process in Sinatra
require 'sinatra'
get '/long_process' do
child_pid = Process.fork do
# hard work is done here...
sleep 10
Process.exit
end