Skip to content

Instantly share code, notes, and snippets.

@sdsykes
sdsykes / desktop_equaliser.rb
Created Nov 24, 2017
Balance desktops after unplugging or plugging in an external monitor using TotalSpaces2
View desktop_equaliser.rb
#!/usr/bin/env ruby
require 'totalspaces2'
columns = TotalSpaces2.grid_columns
displays = TotalSpaces2.display_list()
if displays.size == 1
spaces_count = TotalSpaces2.number_of_spaces
if spaces_count > columns && spaces_count % columns == columns - 1
View gist:df43e9ddaba4dabc05dc
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css">
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:900px; -webkit-transform:rotate(0deg)">
<scene id="scene1" width="300">
<drawing t="translate(0,31)">
@sdsykes
sdsykes / SwapScreens.rb
Created Oct 12, 2015
Uses TotalSpaces2 to swap all windows to the other screen
View SwapScreens.rb
#!/usr/bin/env ruby
require 'totalspaces2'
displays = TotalSpaces2.display_list
if displays.count != 2
puts "Must have 2 displays attached"
exit 1
end
@sdsykes
sdsykes / down.rb
Last active Sep 17, 2015
Scripts to move each direction for TotalSpaces2
View down.rb
require 'totalspaces2'
current = TotalSpaces2.current_space
spaces = TotalSpaces2.number_of_spaces
columns = TotalSpaces2.grid_columns
new_space = current + columns
if new_space <= spaces
TotalSpaces2.move_to_space(new_space)
end
View changeSpace.rb
require 'totalspaces2'
TotalSpaces2.move_to_space(ARGV[0].to_i)
@sdsykes
sdsykes / gist:5c2c0c2a41396aead3b7
Last active Jul 7, 2021
Windows on a space (using private CGS)
View gist:5c2c0c2a41396aead3b7
/// header
id CGSCopyManagedDisplaySpaces(int conn);
int _CGSDefaultConnection();
id CGSCopyWindowsWithOptionsAndTags(int conn, unsigned owner, NSArray *spids, unsigned options, unsigned long long *setTags, unsigned long long *clearTags);
// code
int spaceNumber = 0; // the space you want to get the windows for. numbering starts at 0.
@sdsykes
sdsykes / invert.rb
Last active Aug 29, 2015
A quick and dirty solver for Inverter http://gorried.github.io/inverter/game.html
View invert.rb
$size = ARGV[0].to_i
if $size <= 0
puts "Supply numeric level (grid size) as an argument"
exit
end
def show(placement)
0.upto($size - 1) do |x|
View keybase.md

Keybase proof

I hereby claim:

  • I am sdsykes on github.
  • I am sdsykes (https://keybase.io/sdsykes) on keybase.
  • I have a public key whose fingerprint is 8083 1053 7ED3 36B7 4B12 A80B 90A5 BAEA 6D05 D980

To claim this, I am signing this object:

@sdsykes
sdsykes / mongoid.rb
Created Oct 8, 2011
Fix for mongoid uninitialized constant errors from loading everything in lib in mongoid.rb in initializers
View mongoid.rb
# initializers/mongoid.rb
# for when files in lib depend on or inherit from other files in lib
def do_require(file)
begin
require file
rescue NameError => e
e.message =~ /constant (\w+::)*(\w+)$/
if $2
do_require($2.underscore)
@sdsykes
sdsykes / gist:1184640
Created Aug 31, 2011
scriptingbridge sending keystroke with control key
View gist:1184640
def four_char_code(s)
(s[0].ord << 24) + (s[1].ord << 16) + (s[2].ord << 8) + s[3].ord
end
system = SBApplication.applicationWithBundleIdentifier("com.apple.SystemEvents")
system.send(:"keystroke:using:", space_number.to_s, four_char_code('Kctl'))