Skip to content

Instantly share code, notes, and snippets.

View sgonzalez's full-sized avatar
💭
Crunching tensors.

Santiago Gonzalez sgonzalez

💭
Crunching tensors.
View GitHub Profile
@sgonzalez
sgonzalez / String+zsh.swift
Created June 12, 2019 20:16
Executing commands with zsh in Swift
extension String {
func runAsZshCommandLine() -> String {
let task = Process()
task.launchPath = "/bin/zsh"
task.arguments = ["-l"]
let input = Pipe()
task.standardInput = input
input.fileHandleForWriting.write(self.data(using: .utf8)!)
input.fileHandleForWriting.closeFile()
@sgonzalez
sgonzalez / barometric_formula.h
Created April 15, 2017 00:26
C++ implementation of the barometric formula, based (mostly) on the U.S. Standard Atmosphere model
///////////////////////////////////////////
// Santiago Gonzalez <slgonzalez@me.com> //
///////////////////////////////////////////
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <math.h>
@sgonzalez
sgonzalez / bilerp.c
Last active August 29, 2015 14:21
C Bilinear Interpolation
///////////////////////
// Santiago Gonzalez //
///////////////////////
// Notes:
// - 2d arrays are assumed to be normal arrays with width*height elements (hence the ELEM macro)
// - Point is just a struct with an x and y
#define ELEM(arr, height, i, j) arr[i*height+j]

Keybase proof

I hereby claim:

  • I am sgonzalez on github.
  • I am slgonzalez (https://keybase.io/slgonzalez) on keybase.
  • I have a public key whose fingerprint is 016A 3792 861F 1320 0978 6E9A 3284 3BC5 A3AF 4AA2

To claim this, I am signing this object:

@sgonzalez
sgonzalez / segmented_control_helper.rb
Last active February 16, 2021 19:44
Rails - Bootstrap segmented control in form
# put in application_helper.rb
def segmented_control(f, attribute, names, values, active_value)
haml_tag :div, :class => "btn-group", "data-toggle" => "buttons", style:"display:block; margin-bottom:50px;" do
values.each_with_index do |v, i|
haml_tag :label, :class => "btn btn-default#{active_value == v ? ' active' : ''}" do
haml_concat(f.radio_button attribute, values[i], :checked => (active_value == v))
haml_concat names[i]
end
end
end
@sgonzalez
sgonzalez / welford.rb
Last active December 28, 2015 17:29
Ruby - Welford's single pass mean, standard deviation, variance, min, max, and autocorrelation
#!/usr/bin/ruby
#######################
## Santiago Gonzalez ##
#######################
###
# This is a simple implementation of Welford's single pass equations in Ruby
# Calculates mean, max, min, count, stdev, variance, and autocorrelation
###
@sgonzalez
sgonzalez / rvgs.rb
Last active December 28, 2015 17:29
Ruby - Random Variate Generators
#!/usr/bin/env ruby
#######################
## Santiago Gonzalez ##
#######################
# Bernoulli(p)
# Binomial(n, p)
# Equilikely(a, b)
# Geometric(p)
@sgonzalez
sgonzalez / gist:3859008
Created October 9, 2012 14:02
Ruby - Adding Leading Zeros to Anything
(15 - anything.to_s.length).times { anything = "0#{anything}" } #add leading zeros, where 15 is the total wanted length