Skip to content

Instantly share code, notes, and snippets.

@herenow
herenow / PRICE_VOICE_UPDATE.js
Last active November 30, 2018 16:07
TensorCharts Price Voice Update Script
// Settings
var changeThresholdPct = 1.0; // Notify by voice when the price moves up or down this percentage
var beepChangeThresholdPct = 0.25; // Notify with a beep when the price moves up or down this percentage
// Scopes
var lastPx = self.lastPx;
var beepLastPx = self.beepLastPx;
if(trades.length!=0){
var currentPx = trades[0].Price;
@herenow
herenow / snippet.js
Created July 5, 2018 17:04
Filter coinmarketcap coins by minimum of 100k USD marketcap
$('#currencies-all tbody > tr').filter((i, v) => (window.parseFloat($(v).find('.market-cap').data('usd')) || 0) < 100000000.0).remove()
require 'uri'
require 'net/http'
require 'auth0'
class Auth0Api
def initialize(options = {})
@client_id = options[:client_id] || ENV['AUTH0_CLIENT_ID']
@client_secret = options[:client_secret] || ENV['AUTH0_CLIENT_SECRET']
@domain = options[:domain] || ENV['AUTH0_DOMAIN']
end
@herenow
herenow / application_record.rb
Last active December 2, 2017 02:39
ApplicationRecord (model) debug_id method
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
# Returns a string to be used in log messages.
# Concats the object's class name w/ it's id, so we can easely
# identify and search for the object in log messages.
#
# Example:
#
# user = User.new(id: 25)
@herenow
herenow / geolite2_update.rake
Last active October 30, 2017 16:06
Download latest geolite2 database rake task
require 'open-uri'
namespace :geolite2 do
desc 'Download the latest Maxmind Geolite2 database and dump it into the tmp folder.'
task :update do
required_system_bin = [
'curl',
'tar',
'mkdir',
'find',
<?php
$cep = str_replace('-', '', $POST['id']);
$url = 'http://api.postmon.com.br/v1/cep/'.$cep;
$handle = curl_init();
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_URL, $url);
@herenow
herenow / 01_json_serializer.rb
Last active July 28, 2017 06:07
Pass Virtus/Attribute classes to Rails' ActiveRecord serialize (as json)
# lib/json_serializer.rb
class JsonSerializer
# Dumps objects to json.
# Loads json into specified class.
#
# e.g:
#
# class User
# serialize :data, JsonSerializer.new(DataObject)
# end
@herenow
herenow / object_id.rb
Last active November 25, 2023 09:12
Stripe like id generation in Rails
# app/models/concerns/object_id.rb
module ObjectId
class ObjectIdReservedErr < StandardError; end
class ObjectIdPersistedErr < StandardError; end
def self.included(base)
base.extend ClassMethods
base.send :include, InstanceMethods
end
@herenow
herenow / id_as_string_monkey_patches.rb
Last active June 4, 2017 04:19
Default Rails primary_key and references to string (monkey patch)
# By default, rails expects id's to be a integer
# In our app, we store id's as strings.
#
# To make our life easier, instead of always having to remember this
# and explicitly telling rails the id is a string, I'm going to monkey
# patch some migrations and AR methods.
module CoreExtensions
module ActiveRecord
module ConnectionAdapters
module ReferenceDefinition