Skip to content

Instantly share code, notes, and snippets.

@mrkplt
mrkplt / gist:7fb65807e60e9ce8aec2
Last active August 29, 2015 14:17
Awful coupling, Demeter violation
class A
attr_reader :b
def initialize
@b = B.new
end
end
class B
attr_reader :c
@mrkplt
mrkplt / environment_check.rb
Last active August 29, 2015 14:22
Environment check for safer rake tasks.
module EnvironmentCheck
MESSAGE = "This action is destructive. Proceed?"
def self.execute(message = MESSAGE)
return command_line_output unless inquiry(message) == 'y'
yield if block_given?
end
private
### Keybase proof
I hereby claim:
* I am mrkplt on github.
* I am mrkplt (https://keybase.io/mrkplt) on keybase.
* I have a public key whose fingerprint is B63F B8E1 BE81 FBAF E770 6DB7 2D7F 0EBC 0074 AC2E
To claim this, I am signing this object:
package main
import (
"net/http"
"github.com/mrkplt/end_point/models"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
@mrkplt
mrkplt / com.mrkplt.sockfix.plist
Created October 19, 2011 03:51
Startup script that allows you to use the built in mysql server with Snow Leopard Server and Liip PHP (http://php-osx.liip.ch/) by symlinking the mysql.sock location to where php expects it to be. Goes in /Library/LaunchDaemons. Restart the server.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.mrkplt.sockfix</string>
<key>Program</key>
<string>/bin/ln</string>
<key>ProgramArguments</key>
<array>
@mrkplt
mrkplt / gist:2715219
Created May 17, 2012 00:39
Rails App init with test framework
$ rails new <app_name> --skip-test-unit
$ cd <app_name>/
$ git init
$ git add .
$ git commit -m 'first commit'
$ git remote add origin <git repo>
$ git push -u origin master
$ mate .
/**
@mrkplt
mrkplt / unicorn_example.sh
Created June 21, 2012 23:15 — forked from tualatrix/unicorn_example.sh
An example of unicorn init script for Ubuntu
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
@mrkplt
mrkplt / ldap_auth.rb
Created July 31, 2013 22:12
Ruby script using Net::LDAP (net/ldap) to authenticate a users account name against an ldap server. This is tested against an AD domain. user@example.com is not the user_name our domain expected. Your milage may vary. Credit to a bunch of tutorials for getting this to work (whose tabs I sadly closed). This shoudl enable you with the right creden…
require 'net/ldap'
require 'io/console'
class LDAPUser
def connect(user_name, password)
ldap = Net::LDAP.new(:host => 'example.com', :port => 389)
ldap.auth("CN=#{user_name},OU=Users,DC=example,DC=com", password)
begin
@mrkplt
mrkplt / do-___-end.sublime-snippet
Created December 5, 2013 16:48
doe <tab> creates a do end block in Sublime Text 2. Put this file in ~/Library/Application Support/Sublime Text 2/Packages/Ruby/
<snippet>
<content><![CDATA[
do
${1}
end]]></content>
<description>do...end block</description>
<tabTrigger>doe</tabTrigger>
<scope>source.ruby</scope>
</snippet>
@mrkplt
mrkplt / signal_trapping_example.rb
Created December 16, 2013 19:52
A lil script for playing with signal trapping on *nix machines.
hello = 'Hello'
puts Process.pid
while true
Signal.trap('USR1'){
hello = 'HALLO!'
}
Signal.trap('USR2'){
hello = 'Hello'
}