Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'pathname'
code_files = ARGV
code_files.each do |file|
file = Pathname(file)
contents = file.read
contents.gsub!(/(^#import .*\n)+/) do |imports|
imports = imports.split("\n")
imports.sort.uniq.join("\n") << "\n"
protocol Typed {
typealias Element
func elem() -> Element
}
struct Concrete<T>: Typed {
typealias Element = T
let e: T
func elem() -> T {
return e
@segiddins
segiddins / app
Last active August 29, 2015 14:24
A tiny app launcher
#!/usr/bin/env ruby
app = requested = ARGV.shift
unless File.executable?(app)
escaped_app = app.gsub(/(.)/, '\\\\\1')
app = Dir.glob("/Applications/#{escaped_app}.app/Contents/MacOS/{#{escaped_app},*}").first
end
Process.detach Process.spawn([app, requested], *ARGV, err: '/dev/null', out: '/dev/null')
@segiddins
segiddins / each_ruby
Last active August 29, 2015 14:21
Run a shell command in each rbenv version installed
#!/usr/bin/ruby
versions = `rbenv versions --bare`.split("\n").map(&:strip)
warn "rbenv not installed" && exit(1) unless $?.success?
versions.each do |v|
puts "rbenv shell #{v}"
puts
system({"RBENV_VERSION" => v}, ARGV.join(' '))
puts '-' * 80
@segiddins
segiddins / evil.m
Created April 18, 2015 00:14
I swear, I only did this for an experiment
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
IMP imp = imp_implementationWithBlock(^id(id self, id block, id arg){
NSLog(@"self: %@, arg: %@", self, arg);
return self;
});
class_addMethod([NSObject class], @selector (foo), imp, "@@:@");
#!/usr/bin/env cato 1.2
import Foundation
class OptCls: NSObject {
dynamic var s: String?
dynamic var nos: String = ""
dynamic var nss: NSString?
dynamic var ius: String!
dynamic var i: Int = 0
func drop<S: SequenceType, T where S.Generator.Element == T>(sequence: S, count: Int) -> GeneratorOf<T> {
var generator = sequence.generate()
for _ in 0..<count {
generator.next()
}
return GeneratorOf<T>(generator)
}

Keybase proof

I hereby claim:

  • I am segiddins on github.
  • I am segiddins (https://keybase.io/segiddins) on keybase.
  • I have a public key ASBUfziuAe8qODgXz8UeuEIre6ZlOV8BdSUn4RcyApdEYAo

To claim this, I am signing this object:

#!/usr/bin/ruby
require 'json'
require 'open-uri'
gems = %w(rails capybara bundler)
specs = []
begin
@segiddins
segiddins / update_shared
Last active November 1, 2015 19:10
Update web repos' shared submodule
#!/usr/bin/env ruby
SHARED_PATH = 'shared'
Dir.glob('*segiddins.me').each do |repo|
Dir.chdir repo do
unless `command git status` =~ /working directory clean/
puts "The working directory for #{repo} is dirty"
end
pull = ''
shared_sha = ''