Skip to content

Instantly share code, notes, and snippets.

$('form#new_task').submit(function() {
$.ajax({
type: "POST",
url: $(this).attr('action'), //sumbits it to the given url of the form
data: {
data_1: value_1,
data_2: value_2
}, //input gui di
dataType: "HTML",
success(function(result){
@tmm1
tmm1 / ruby19_date_marshal.rb
Created February 6, 2013 06:07
Fix marshal incompatibility between Date/DateTime on 1.8 and 1.9
require 'date'
class Date
if RUBY_VERSION < '1.9'
## accept 1.9 marshaled data on 1.8
## based on ext/date/date_core.c d_lite_marshal_dump_old
def marshal_load(data)
nth, jd, df, sf, of, @sg = data
real_jd =
@ches
ches / follow_observer_spec.rb
Last active April 9, 2025 10:36
Example of testing Rails observers in isolation for cross-cutting concerns
require 'spec_helper'
# Bustle is a pubsub system used for activity streams:
# https://github.com/fredwu/bustle
#
# Here when a person follows another (or a discussion, for instance), the observer wires
# up pubsub between them for future activity notifications. The Follow model knows nothing
# about the implementation choices for the pubsub system.
describe FollowObserver do
subject { FollowObserver.instance }
r53 = AWS::Route53.new(
:access_key_id => 'aws-key-id',
:secret_access_key => 'aws-secret-key')
response = r53.client.list_resource_record_sets(
:hosted_zone_id => "zone-id",
:start_record_name => 'xxx.example.com',
:start_record_type => 'CNAME'
)
puts response[:resource_record_sets].map{|r| r[:name]}
@karlseguin
karlseguin / spec.go
Last active February 20, 2018 19:42
A simple test helper for Go. See http://openmymind.net/Testing-In-Go/
package tests
import (
"testing"
)
type S struct {
t *testing.T
}
#!/usr/bin/env python3
import csv
import datetime
import collections
Treatment = collections.namedtuple('Treatment', 'date_funded, funds_sent, status')
with open('patients.csv') as csvfile:
spamreader = csv.reader(csvfile, delimiter='\t')
@ashrithr
ashrithr / kafka.md
Last active March 14, 2024 21:16
kafka introduction

Introduction to Kafka

Kafka acts as a kind of write-ahead log (WAL) that records messages to a persistent store (disk) and allows subscribers to read and apply these changes to their own stores in a system appropriate time-frame.

Terminology:

  • Producers send messages to brokers
  • Consumers read messages from brokers
  • Messages are sent to a topic
@jordelver
jordelver / gist:5998870
Last active January 13, 2017 07:23
Find where stuff broke using git bisect with cucumber

Find where stuff broke using git bisect with Cucumber

Start git bisect

git bisect start

Specify a good and bad commit

git bisect good <commit-where-stuff-is-working>
@TSMMark
TSMMark / s3.rb
Last active March 4, 2022 20:17
Process a remote CSV with SmarterCSV (also example with Paperclip and Amazon S3 AWS)
# this is the code I used to determine the csv_path to use when using Paperclip with Amazon S3 AWS
# necessary because my development environment doesn't upload to S3
# get an object that has_attachment with Paperclip
object = ModelWithPaperclip.last
# use url if no file exists at path
csv_path = File.exists?(object.csv.path) ? object.csv.path : object.csv.url
# this should probably be implemented as a model method
@justinas
justinas / 1_singlehost.go
Last active November 29, 2023 11:41
Go middleware samples for my blog post. http://justinas.org/writing-http-middleware-in-go/
package main
import (
"net/http"
)
type SingleHost struct {
handler http.Handler
allowedHost string
}