Skip to content

Instantly share code, notes, and snippets.

View trmcnvn's full-sized avatar
✌️

Thomas McNiven trmcnvn

✌️
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Pixel.Extensions
{
// http://stackoverflow.com/questions/8025890/is-there-a-much-better-way-to-create-deep-and-shallow-clones-in-c/8026574#8026574
public static class DeepCloneEx
{
public static T DeepClone<T>(this T original)
@trmcnvn
trmcnvn / irc.go
Created March 26, 2014 15:43
irc.go
package irc
import(
"net/textproto"
"regexp"
"time"
)
var (
privmsg = regexp.MustCompile("^:([a-zA-Z0-9`_\\-]+)![a-zA-Z0-9/\\\\\\.\\-]+@[a-zA-Z0-9/\\\\\\.\\-]+ PRIVMSG (#[a-zA-Z0-9]+) :(.*)$")
@trmcnvn
trmcnvn / market.rb
Last active November 3, 2016 15:45
# Uses Steam Market backend URL to list cheapest knife available for CS:GO
# Checks if price is under the threshold and if so alert us
require 'httparty'
require 'nokogiri'
class Market
def initialize
# {"success":true,"start":0,"pagesize":100,"total_count":362,"results_html": ...}
@url = "http://steamcommunity.com/market/search/render/?query=appid%3A730%20Covert%20Knife&start=0&count=1&sort_dir=asc&sort_column=price"
# https://github.com/jrgifford/delayed_paperclip/blob/master/lib/delayed_paperclip/attachment.rb#L94
# delayed_paperclip uses ActiveRecord::Relation#update_all which does not invoke
# ActiveRecord callbacks such as after_save, this patch changes the update method
# to use ActiveRecord::Relation#update
module DelayedPaperclip
module Attachment
module InstanceMethods
private
def update_processing_column
@trmcnvn
trmcnvn / irc.go
Created September 5, 2014 08:23
irc regex example
package main
import (
"fmt"
"regexp"
)
// Valid Go regexp: https://code.google.com/p/re2/wiki/Syntax
var fixtures []string = []string{

Keybase proof

I hereby claim:

  • I am vevix on github.
  • I am vevix (https://keybase.io/vevix) on keybase.
  • I have a public key whose fingerprint is 5339 A16C 444A 97BC 032F 2380 8962 FE71 D808 7F83

To claim this, I am signing this object:

function confirm() {
CustomEvent.observe(LiveEvents.LIVE_BEFORE_WINDOW_LOAD, function(win) {
if (win.toString() !== "LiveWindowChatFloating") return;
win.box.setToolbarCloseOnClick(function() {
var confirm = window.confirm("Are you sure?");
if (confirm !== false) {
CustomEvent.fire(LiveEvents.LIVE_EVENT, LiveEvents.LIVE_LEAVE_CHANNEL, this);
this.fire(LiveEvents.WINDOW_CLOSE);
}
# Faster random records
module ActiveRecord
class Base
def self.random(limit = 1)
if (total = count) > 0
highest_possible_offset = [0, total - limit].max
offset = [rand(total), highest_possible_offset].min
num = [limit, total].min
offset(offset).limit(num)
else
@trmcnvn
trmcnvn / application.template.hbs
Created September 26, 2015 02:39
Routable Components
{{outlet}}
-module(Game).
-export([check_anytrips/1, check_two_dice/3]).
check_anytrips(dice_roll) ->
value = num(uniq(dice_roll)),
value == 1.
check_two_dice(dice_roll, key, value) ->
lists:member(dice_roll, key) && lists:member(dice_roll, value).