Skip to content

Instantly share code, notes, and snippets.

@aquajach
aquajach / index.html
Created May 15, 2017 04:04
Tableau embedded charts without toolbar
<div style="overflow-y: hidden; height: 440px; width: 1000px">
<div class='tableauPlaceholder' id='viz1494212367852' style='position: relative; float: left'>
<noscript>
<a href='#'>
<img alt='Sheet 1 ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;Fr&#47;FreeDutyEngagement&#47;Sheet1&#47;1_rss.png' style='border: none' />
</a>
</noscript>
<object class='tableauViz' style='display:none;'>
<param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' />
<param name='site_root' value='' />
@aquajach
aquajach / code_smells.rb
Last active April 28, 2017 05:33
Code smells
((total_scans*1.0)/total_campaign_members).round(1)
#=>
((total_scans * 1.0) / total_campaign_members).round(1)
validates_numericality_of :transaction_unit, 'greater_than' => 0, 'allow_nil' => true
#=>
validates_numericality_of :transaction_unit, greater_than: 0, allow_nil: true
WechatMessageJob.perform_later({openid: openid, article: wechat_article })
#=>
@aquajach
aquajach / coffeescript2jsx.js.jsx
Created February 22, 2017 10:42
CoffeeScript => ES6 + JSX
// CoffeeScript:
// @CampaignList = React.createClass
//
// render: ->
// div { className: 'content-wrapper' },
// for campaign in @props.data
// React.createElement(CampaignCard,
// key: campaign.id
// campaign: campaign
// )
@aquajach
aquajach / gist:9e22ed972d06c9f41825d2f9a8f4f300
Last active February 6, 2017 03:36
User Agent of iOS QR Scanners
#1 QR Reader (https://itunes.apple.com/us/app/qr-reader-for-iphone/id368494609?mt=8)
--------
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Mobile/14A456 Safari
--------
=> Double stack button
QR Scanner
--------
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Mobile/14A456
--------
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'active_record'
require 'rspec/core/rake_task'
require 'appraisal'
require 'pg'
RSpec::Core::RakeTask.new :spec
Bundler::GemHelper.install_tasks
@aquajach
aquajach / coin_change.rb
Created April 26, 2016 03:08
Coin changes solved by recursion
def coin_change(coins, amount)
coins = coins.sort
coin = coins.first
multiples = (0..(amount / coin)).map{|division| division * coin}
solution = amount
if coins.count == 1
if amount % coin != 0
return -1
else
@aquajach
aquajach / protected_zipped_csv_json.rb
Last active April 27, 2022 07:04
Password protected zip file with csv/json data inside
compressed_filestream = Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |zos|
#First file
zos.put_next_entry "test1.csv"
csv = CSV.generate do |csv|
User.all.each do |user|
csv << [user.id, user.name]
end
csv << values
end
zos.print csv
@aquajach
aquajach / read_attribute_before_type_castVSread_attribute.rb
Created February 19, 2016 02:42
read_attribute_before_type_cast is 50% faster than read_attribute when type casting is required
require 'benchmark'
person = Person.new(created_at: '2016-2-19')
time_1 = Benchmark.realtime do
100000.times do
person.read_attribute_before_type_cast(:created_at)
end
end
time_2 = Benchmark.realtime do
@aquajach
aquajach / NSMutableAttributedString+Extend.swift
Last active June 2, 2021 21:31
Swift: Highlight matched text in String between square brackets
import UIKit
extension NSMutableAttributedString {
func highlightTarget(target: String, color: UIColor) -> NSMutableAttributedString {
let targetValue = String(target.characters.dropFirst().dropLast())
let regPattern = "\\[\(targetValue)\\]"
if let regex = try? NSRegularExpression(pattern: regPattern, options: []) {
let matchesArray = regex.matchesInString(self.string, options: [], range: NSRange(location: 0, length: self.length))
for match in matchesArray {
@aquajach
aquajach / rbenv-2.2.3
Created November 12, 2015 04:52
ruby-build: definition not found: 2.2.3
$cd ~/.rbenv/plugins/ruby-build
$git pull