Skip to content

Instantly share code, notes, and snippets.

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

Stephen Baidu stephenbaidu

🏠
Working from home
  • Microsoft
  • Redmond, WA
View GitHub Profile
# ***********************************************************************
# Ruby script to flip through my tomod pictures for the MH370
# For Mac users only. Uses AppleScript.
# ***********************************************************************
# ***********************************************************************
# Alert
# ***********************************************************************
puts "Starting in 10 seconds"
@stephenbaidu
stephenbaidu / immutable.rb
Created March 8, 2017 23:41
Include Ruby/Rails module with arguments/options
# Usage
class Payment < ActiveRecord::Base
# Readonly columns
include Immutable.for :customer_id, :amount
end
# Implementation 1: Rails Concern
module Immutable
extend ActiveSupport::Concern
def flatten(element)
return [element] unless element.is_a?(Array)
element.map{|e| flatten(e) }.inject(:+)
end
class FlattenArray
attr_reader :result
def initialize(array)
@array = array
end
def call
@result = flatten(@array) || []
@result
# ~/.railsrc
--database=postgresql
--skip-test-unit
--skip-turbolinks
--skip-spring
--skip-coffee
--skip-bundle
module Resourcify
extend ActiveSupport::Concern
included do
before_action :set_resource, only: [:show, :update, :destroy]
end
def index
@resources = resource_class.all
end
//
// main.cpp
// SortingAlgorithms
//
// Created by Stephen Baidu on 9/8/14.
// Copyright (c) 2014 Stephen Baidu. All rights reserved.
//
#include <iostream>
#include <vector>
# ~/.bash_profile
# You can load both rvm and asdf in ~/.bash_profile
# This makes it easy to switch what to load
# RVM
# source $HOME/.rvm/scripts/rvm
# ASDF
. $HOME/.asdf/asdf.sh
Function SimpleContextMenu {
param (
[Parameter(Mandatory, Position = 0)]
[System.Object]
$List,
[Parameter(Mandatory = $false, Position = 1)]
[string]
$Header = "Select"
)
# Git Helpers
function fn_git_branch { & git branch }
New-Alias -Name gb -Value fn_git_branch -Force -Option AllScope
function fn_git_checkout_master { & git checkout master }
New-Alias -Name master -Value fn_git_checkout_master -Force -Option AllScope
New-Alias -Name gb -Value fn_git_branch -Force -Option AllScope
function fn_git_checkout_main { & git checkout main }
New-Alias -Name main -Value fn_git_checkout_main -Force -Option AllScope
function fn_git_status { & git status }
New-Alias -Name gs -Value fn_git_status -Force -Option AllScope