Skip to content

Instantly share code, notes, and snippets.

View buhrmi's full-sized avatar

Stefan Buhrmester buhrmi

View GitHub Profile
@buhrmi
buhrmi / gist:763374
Created January 3, 2011 11:32
A hacky DataMapper monkey patch to mark properties as dirty even if they have not changed
module DataMapper
module Resource
def taint! property
self.persisted_state = State::Dirty.new(self) unless self.persisted_state.kind_of?(State::Dirty)
self.persisted_state.original_attributes[properties[property]] = Object.new
end
end
end
# Example:
@buhrmi
buhrmi / gist:800007
Created January 28, 2011 08:48
A haml filter that let's you call client javascript in ruby, utilizing Rjs
# In config/initializers/haml_filters.rb
module Haml
module Filters
module Client
include Base
def compile(precompiler, text)
return if precompiler.options[:suppress_eval]
precompiler.instance_eval do
push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
@buhrmi
buhrmi / gist:801746
Created January 29, 2011 10:57
Pessimistic Locking Strategy support for DataMapper (FOR UPDATE)
# This Patch makes it possible to retrieve row-locked records from data-objects repositories
# Sample Usage: User.locked.get(1)
# #=> SELECT [...] WHERE `id` = 1 ORDER BY `id` LIMIT 1 FOR UPDATE
# In user.rb
def self.locked
all(:with_locking => true)
end
# The actual patch
@buhrmi
buhrmi / gist:1344659
Created November 7, 2011 10:51
Sublime Text 2 Git Annotation Colors
<dict>
<key>name</key>
<string>Git Modified Line</string>
<key>scope</key>
<string>git.changes.x</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#272852</string>
</dict>
class App < Sinatra::Base
include Jazzband
get '/' do
session['username'] = params['username']
haml session['username'] ? :chat : :select_username
end
get '/send' do
return 403 unless session['username']

Keybase proof

I hereby claim:

  • I am buhrmi on github.
  • I am buhrmi (https://keybase.io/buhrmi) on keybase.
  • I have a public key whose fingerprint is 590E 0550 A897 8490 8834 77C6 524F 17C7 B8C0 E435

To claim this, I am signing this object:

0xfc1B532F8ED8Ad01512eF71c588763E5A0CaBc02
@buhrmi
buhrmi / actioncable-vue.js
Last active October 29, 2018 09:45
Vue ActionCable
// Make a vue component automatically subscribe to a cable and unsubscribe when it's destroyed
// You can use reactive vue state as params. the subscription will be re-established when the param changes.
// Usage //
// new Vue
// data: ->
// something: null
// subscriptions:
// SomeChannel:
// params: ->
@buhrmi
buhrmi / index.html
Last active October 30, 2018 08:20
shitcoin maker
<div id="app">
<pre>
pragma solidity ^0.4.24;
/**
* Thank you for checking out {{ name }}.
* We hope you have an amazing day.
*/
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol
// On each page load, any element with a [data-svelte] attribute gets injected with
// the component defined in this attribute. Eg `data-svelte="poker"` will load the
// `poker.svelte` component into that element.
const req = require.context('../', true, /\.(svelte)$/i);
const components = {}
req.keys().map(key => {
const name = key.match(/\w+/)[0];
components[name] = req(key).default || req(key)
});