Skip to content

Instantly share code, notes, and snippets.

View danini-the-panini's full-sized avatar

Dani Smith danini-the-panini

View GitHub Profile
@danini-the-panini
danini-the-panini / inheritance.rb
Created August 23, 2023 07:54
Ruby Private and Protected examples
class Foo
def call_foo
foo
end
def call_self_foo
self.foo
end
@danini-the-panini
danini-the-panini / main.rb
Last active March 11, 2022 07:35
reject! vs next
require 'benchmark/ips'
N = 1_000_000
ARRAY = N.times.map { rand }
Benchmark.ips do |x|
x.report("reject") do
arr = ARRAY.dup
out = []
arr.reject! { _1 >= 0.5 }
@danini-the-panini
danini-the-panini / github_aliases.ps1
Last active May 3, 2021 21:29
Powershell Github aliases ported from oh-my-zsh git plugin
Function current_branch { git rev-parse --abbrev-ref HEAD }
Function ga { git add @Args }
Function gau { git add --update @Args }
Function gaa { git add --all @Args }
Function gapa { git add --patch @Args }
Function gb { git branch @Args }
Function gba { git branch -a @Args }
Function gbd { git branch -d @Args }
Function gbl { git blame -b -w @Args }
Function gbnm { git branch --no-merged @Args }
@danini-the-panini
danini-the-panini / fixture_test.rb
Last active August 7, 2020 15:24
Rails Fixtures Test
# Test validity of all your fixtures in one simple test.
# Just put this file somewhere, like maybe `test/models`, and run `bin/rails test test/models/fixture_test.rb`.
# Even gives you the line number of the fixture definition in the failure message!
require 'test_helper'
class FixturesTest < ActiveSupport::TestCase
Dir.glob(Rails.root.join('test', 'fixtures', '*.yml')).each do |filename|
set_name = File.basename(filename, '.yml')
@danini-the-panini
danini-the-panini / main.rb
Created June 9, 2019 08:42
Benchmark JSON parsing with symbol keys
require 'active_support/core_ext/hash'
require 'benchmark/ips'
require 'json'
N = 1000
M = 100
TEST_ARRAY = N.times.map do |n|
h = { 'some_key' => "H #{n}" }
M.times do |m|
@danini-the-panini
danini-the-panini / rein_schema_dumper.rb
Created October 19, 2018 13:01
Partial schema dumber for nullobject/rein. Supports only numerical check constraints on PostgreSQL
module Rein::SchemaDumper
def tables(stream)
super
check_constraints(stream)
end
def check_constraints(stream)
constraints = @connection.execute <<-SQL
select *
from information_schema.check_constraints as c, information_schema.constraint_column_usage as u
N = 960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719
def tupper(x, y)
0.5 < (((y/17).floor*(2 ** (-17 * x.floor - (y.floor % 17)))) % 2).floor
end
(N..N+16).each do |y|
105.downto(0) do |x|
print tupper(x, y) ? "\e[47m" : "\e[40m";
print ' '
@danini-the-panini
danini-the-panini / StringCalculator.playground
Created February 18, 2015 08:18
String Calculator in Swift
import Foundation
class StringCalculator {
func add(string:String) -> Int {
let numbers = string.componentsSeparatedByString(",")
var total = 0
for number in numbers {
total += (number as NSString).integerValue
}
return total
@danini-the-panini
danini-the-panini / whatismyip.bat
Created January 8, 2014 11:23
Quick global IP getter script (puts IP in clipboard for pasting in IM's etc.) Works in Windows Vista, 7, 8
@echo off
echo Getting your IP address...
echo.
curl ifconfig.me | clip
echo.
echo Your IP is in the clipboard :)
echo.
pause