Skip to content

Instantly share code, notes, and snippets.

View dkam's full-sized avatar

Dan Milne dkam

View GitHub Profile
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
XSL = <<-EOXSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:param name="indent-increment" select="' '"/>
<xsl:template name="newline">
@Burgestrand
Burgestrand / README.md
Created February 3, 2012 23:20
A ruby script to construct magnet links out of .torrent files

Magneto

It reads your torrents. Spit out magnet URIs.

Example Usage

$ ./magneto.rb magneto.rb.torrent

Results in:

@ascendbruce
ascendbruce / ruby-how-to-check-string-valid-json-object.md
Last active December 22, 2023 06:39
Ruby test if a string is an valid json object

Background

I posted this gist a few years ago as a quick memo for myself. I never expect this little gist to rank up in top 3 search result and getting so many helpful feedbacks. Since it gets viewed quite often, I decided to revise this post so that it may be a little more helpful. Thank you again for the feedback!

The new answer

require "json"

class MyJSON
@jcupitt
jcupitt / trim.rb
Last active April 30, 2023 02:32
auto-crop in ruby-vips
#!/usr/bin/env ruby
# "trim" is nnow built in, so this is easy
require 'vips'
im = Vips::Image.new_from_file(ARGV[0])
left, top, width, height = im.find_trim
im = im.crop(left, top, width, height)
@rob-murray
rob-murray / find_dups.rb
Last active November 8, 2024 09:21
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
duplicate_records = Model.where.not(id: Model.select("MIN(id) as id").group(columns_that_make_record_distinct))
@dkam
dkam / compile-ffmpeg.sh
Created August 18, 2020 12:38 — forked from wildrun0/compile-ffmpeg.sh
Compiling ffmpeg for Raspberry Pi 4
#!/bin/bash
# Note that there's no libdrm because this lib cause errors
sudo apt update -y && sudo apt upgrade -y
sudo apt-get -y install \
autoconf \
automake \
build-essential \