Skip to content

Instantly share code, notes, and snippets.

@RadhikaG
RadhikaG / heap.py
Last active December 13, 2016 13:57
A short script to demonstrate the different operations on heaps.
global heap
global currSize
def parent(i): #returns parent index of ith index
return i/2
def left(i): #returns left child of ith index
return 2*i
def right(i): #returns right child of ith index
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active March 12, 2025 21:24
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@janko
janko / 01-activerecord.rb
Created May 27, 2015 22:50
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
require "active_record"
ActiveRecord::Base.establish_connection('postgres:///testing')
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.class_eval do
create_table :played_quizzes, force: true do |t|
t.integer :player_ids, array: true
t.json :quiz_snapshot
end
@itsthatguy
itsthatguy / foo.coffee
Last active August 29, 2015 14:16
Coffeescript Classes: object.prototype.function and object.function demonstrated
# Run the following command in shell:
# curl -s https://gist.githubusercontent.com/itsthatguy/48d9b47dba05b300c65b/raw/80b1111bb5273697d1db4f5662eb763aa4a80cdc/foo.coffee | coffee --stdio
class Foo
name: 'abott'
@myFunction: ->
console.log "\n# start"
console.log "\nFoo"
console.log "this.name:", this.name
myOtherFunction: ->
console.log "\nfoo (instance of Foo)"

TIL attr_* methods are optomized.

class Whatever
  def foo
    @foo
  end

  attr_reader :bar
end
class CreateUserForm
include ActiveModel::Model
attr_accessor :email
attr_accessor :name
def initialize
@user = User.new
end
module Publisher
extend self
# delegate to ActiveSupport::Notifications.instrument
def broadcast_event(event_name, payload={})
if block_given?
ActiveSupport::Notifications.instrument(event_name, payload) do
yield
end
else
@himerzi
himerzi / Game of Life
Created March 20, 2014 17:06
The Game of Life in Clojure, and rendered in Quil
(ns game-of-life.core
(:require [quil.core :as q])
(:use overtone.at-at))
(defn game-func
"function taking a game state to the following game state"
[state]
nil)
@ka8725
ka8725 / gist:9419051
Created March 7, 2014 20:12
mailtatcher replacement
$ python -m smtpd -n -c DebuggingServer localhost:1025
This is how receiving email looks like:
---------- MESSAGE FOLLOWS ----------
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: User activation - localhost:8000
From: info@google.ru
@davidzchen
davidzchen / sample-linux.c
Last active August 12, 2025 10:50
Sample C code using the Linux kernel coding style
/*
* Sample file using the Linux kernel coding convention.
*
* https://www.kernel.org/doc/Documentation/CodingStyle
*
* General rules:
* - Indents are tabs and must be 8 spaces wide.
* - Each line must be at most 80 characters long.
* - Use C-style comments.
* - File names should be lower-case.c