Skip to content

Instantly share code, notes, and snippets.

@cpatni
cpatni / app.rb
Created November 21, 2011 22:39
unique calculation using redis
require 'sinatra'
require 'redis'
require 'json'
require 'date'
class String
def &(str)
result = ''
result.force_encoding("BINARY")
@gfontenot
gfontenot / gist:1203520
Created September 8, 2011 14:25
Get duration of a video file with Ruby and FFMpeg
def get_movie_duration video_file
# Run ffmpeg on the video, and do it silently
ffmpeg_output = `/usr/local/bin/ffmpeg -i "#{video_file}" 2>&1`
# Find the duration in the output, and force a return if it's found
/duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})/i.match(ffmpeg_output) { |m| return m[1] }
# If it didn't get a match, something is wrong. Log the error
return "FFMPEG ERROR"
@kerlin
kerlin / get_workers.rb
Last active November 17, 2021 02:03
Calling the Workday API in Ruby with Savon
#!/usr/bin/env ruby
#
# Example Ruby CLI script to retrieve worker data from Workday
# Call on command line with worker id; prints worker name
# add "request" or "response" after worker id and prints the
# outgoing xml or received hash and exits.
#
# Using Savon version 2 for the SOAP client (2.11.2)
#
# Savon defaults to making the message tag the same as the operation name
@myronmarston
myronmarston / ways_to_use_vcr.rb
Created April 13, 2012 15:00
Ways to use VCR for a request made by a let block
# 1) Use VCR.use_cassette in your let block. This will use
# the cassette just for requests made by creating bar, not
# for anything else in your test.
let(:foo) { VCR.use_cassette("foo") { create(:bar) } }
it "uses foo" do
foo
end
# 2) Wrap the it block that uses #foo in VCR.use_cassette.
@vicalejuri
vicalejuri / django-crossdomainxhr-middleware.py
Created June 5, 2010 17:47
Middlware to allow's your django server to respond appropriately to cross domain XHR (postMessage html5 API).
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
#!/usr/bin/env ruby
# Aside from removing Ruby on Rails specific code this is taken verbatim from
# mislav's git-deploy (http://github.com/mislav/git-deploy) and it's awesome
# - Ryan Florence (http://ryanflorence.com)
#
# Install this hook to a remote repository with a working tree, when you push
# to it, this hook will reset the head so the files are updated
if ENV['GIT_DIR'] == '.'
@willurd
willurd / Getting started with requirejs.md
Last active December 14, 2022 08:15
A short introduction to require.js

This is a small collection of scripts showing how to use require.js. It's only one of several ways of setting up a require.js project, but it's enough to get started.

At its core, require.js is about three things:

  1. Dependency management
  2. Modularity
  3. Dynamic script loading

The following files show how these are achieved.

@leegonzales
leegonzales / ChatGPT-Writing Style Analyzer.txt
Last active February 3, 2023 03:34
ChatGPT Prompt: Writing Style Analyzer
Prompt Chaining -
Priming Prompt: “For today's task, you are going to be acting like a highly capable and skilled analyst with excellent attention to detail. You will be tasked with analyzing a writing sample and generating a list of instructions on how to mimic the writing style of the sample. This will require excellent analytical skills and the ability to identify and analyze a variety of writing style attributes, as well as strong language skills to communicate your instructions effectively. Overall, you will need to be highly capable and skilled at analyzing and mimicking writing styles in order to complete this task successfully.”
Tasking Prompt:
“Now - your task is to analyze a writing sample provided below inside {writing sample} and generate a list of instructions on how to mimic the writing style of the sample. These instructions will guide future writing so they must effectively convey the desired writing style, and should be written in affirmative language. Be sure to consider a variety of attrib
@eduncan911
eduncan911 / Revert-Gist.md
Last active July 20, 2023 09:41
Revert Gist Commits

Revert / Undo a Gist Commit

It was not exactly obvious. Here's how to revert a Gist commit!

Checkout the gist like a normal git repo:

# replace the Gist ID with your own
git clone git@github.com:cc13e0fcf2c348cc126f918e4a3917eb.git

Treat it like a normal repo. Edit, force push, etc.

Realtime Notifications with ActionCable

In this episode we're going to be adding realtime notifications into your app using ActionCable. We've talked about notifications a few times in the past and we used AJAX polling for that. 95% of the time, polling is the solution that would be recommended for it.

But if you're looking for a good introduction into ActionCable then this is a decent one because we're only really using it for one way from the server side to the client side.

Getting started

So to get started we're starting with an app that has Bootstrap installed and then we created a Main controller with an index view which is where we will list our Notifications as for this example.

Before we generate our channels let's install a few things