Skip to content

Instantly share code, notes, and snippets.

View awesome's full-sized avatar

So Awesome Man awesome

View GitHub Profile
@awesome
awesome / gist:56677ba7bcfab364bc826024ab371e2f
Created February 7, 2019 00:39 — forked from yurikoval/gist:3663539
Passing arguments to an around_filter
# app/controller/articles_controller.rb
around_filter { |controller, action| controller.send(:add_published_scope, Article){ action.call } }
# app/controller/application_controller.rb
def add_published_scope(klass = nil, &block)
unless klass
klass = controller_name.classify.constantize
end
klass.with_scope(:find => klass.where("published_at <= ?", Time.zone.now)) do
yield
@awesome
awesome / print_amf.rb
Created June 28, 2017 04:32 — forked from jcward/print_amf.rb
RocketAMF can de/serialize AMF serialized byte streams, but it throws (at least, the 0.2.1 version from gem install throws) when it encounters an IExternalizable type in the byte steam. This patch allows it to parsed custom IExternalizable classes properly.
#!/usr/bin/env ruby
require 'rocketamf'
require 'stringio'
# Monkey patch for RocketAMF (0.2.1 gem) that handles IExrternalizable types
# in the input, storing their type as "__as3_type" parameter:
module RocketAMF
module Values #:nodoc:
class TypedHash
@awesome
awesome / print_amf.rb
Created June 28, 2017 04:32 — forked from jcward/print_amf.rb
RocketAMF can de/serialize AMF serialized byte streams, but it throws (at least, the 0.2.1 version from gem install throws) when it encounters an IExternalizable type in the byte steam. This patch allows it to parsed custom IExternalizable classes properly.
#!/usr/bin/env ruby
require 'rocketamf'
require 'stringio'
# Monkey patch for RocketAMF (0.2.1 gem) that handles IExrternalizable types
# in the input, storing their type as "__as3_type" parameter:
module RocketAMF
module Values #:nodoc:
class TypedHash
@awesome
awesome / scraper.rb
Created June 27, 2017 20:11 — forked from melborne/scraper.rb
Text Upside Down with Ruby. data source: twitter→ɹəʇʇɪʍʇのように英数字を180度回転して表示する方法|Colorless Green Ideas http://id.fnshr.info/2013/01/25/upsidedowntext/
# encoding: UTF-8
require "nokogiri"
require "open-uri"
class Scraper
class << self
def build(path, target)
parse get(path), target
end
@awesome
awesome / favicon-from-png.sh
Created March 23, 2017 12:27 — forked from antonklava/favicon-from-png.sh
Super simple script to create a favicon.ico from specified png
#!/bin/bash
#
# Super simple script to create a favicon.ico from specified png.
# Requires imagemagick ( http://www.imagemagick.org )
#
# Usage:
# ./favicon-from-png.sh myimage.png
# ls
# myimage.png favicon.ico
#
@awesome
awesome / chunkypixel_average.rb
Created March 23, 2017 10:51 — forked from darkleo/chunkypixel_average.rb
Pixelizing images with ChunkyPNG
#! usr/bin/env ruby
require 'chunky_png'
class ChunkyPNG::Image
# s: Integer (pixel size)
def pixelize s = 10
temp = Array.new((height*1.0/s).ceil) {Array.new((width*1.0/s).ceil) {Array.new(3) {0}}}
height.times {|j| width.times {|i| ChunkyPNG::Color.to_truecolor_bytes(get_pixel(i,j)).each.with_index {|e,k| temp[j/s][i/s][k] += e}}}
png = ChunkyPNG::Image.new width, height
sq = s**2
@awesome
awesome / gemspec
Created March 21, 2017 05:58 — forked from defunkt/gemspec
Quickly create a gemspec.
#!/usr/bin/env ruby
# Usage: gemspec [-s] GEMNAME
#
# Prints a basic gemspec for GEMNAME based on your git-config info.
# If -s is passed, saves it as a GEMNAME.gemspec in the current
# directory. Otherwise prints to standard output.
#
# Once you check this gemspec into your project, releasing a new gem
# is dead simple:
#
@awesome
awesome / character_set_and_collation.rb
Created March 15, 2017 12:49 — forked from tjh/character_set_and_collation.rb
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@awesome
awesome / firebase-online-user-count-example.md
Created March 6, 2017 08:29 — forked from ajaxray/firebase-online-user-count-example.md
Keep list (and count) of online users in a Firebase web app - by isolated rooms or globally

Gathering.js - How to use

Keep list (and count) of online users in a Firebase web app - by isolated rooms or globally.

Live Demo

Firebase Shared Checklist is a demo application that shows the number of users joined a checklist using gathering.js. Here is a 1 minute screencast of using this application.

@awesome
awesome / fruits-components.html
Created March 6, 2017 07:15 — forked from mmfilesi/fruits-components.html
how combine polymer with handlebars
<dom-module id="fruit-component">
<template>
<p>color: {{color}}</p>
<button on-tap="setColor">set color in light dom</button>
</template>
<script>
Polymer({
is: 'fruit-component',