Skip to content

Instantly share code, notes, and snippets.

My Atom config

@rin
rin / my_object.rb
Created April 13, 2017 11:25 — forked from anonymous/my_object.rb
Custom Validator for JSON in Rails
class MyObject < ActiveRecord::Base
class JsonValidator < ActiveModel::EachValidator
def initialize(options)
options.reverse_merge!(:message => :invalid)
super(options)
end
def validate_each(record, attribute_before_typecast, value)
attribute = attribute_before_typecast.to_s.sub('_before_type_cast', '')
value = value.strip if value.is_a?(String)
@rin
rin / VideoPreview.jsx
Last active September 20, 2018 10:35
React component for videojs
import React, { Component } from 'react';
import { PropTypes as T } from 'prop-types';
import videojs from 'video.js';
// a component for use with videojs
// use it like this:
// <VideoPreview video={myVideo} key={myVideo.id} />
export default class VideoPreview extends Component {
ref = React.createRef();
@rin
rin / bugsnag.js
Created February 5, 2019 02:20
Bugsnag Grouping Hash
bugsnagClient.notify(new Error('Page not found (404)'), {
beforeSend: (report) => {
report.groupingHash = report.request.url;
report.severity = 'info';
},
})
@rin
rin / aws-lambda-youtube-dl.js
Created December 23, 2020 19:30
AWS Lambda to download youtube videos to S3
// To use this, put it in a folder, install ytdl-core with `npm i ytdl-core`, then create a ZIP with the content of the folder and deploy it.
// https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies
var AWS = require('aws-sdk');
const ytdl = require('ytdl-core');
const stream = require('stream');
var s3 = new AWS.S3();
exports.handler = async (event, context, cb) => {
const { videoUrl, key, bucket } = event;