(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| require 'openssl' | |
| def encrypt_string(str) | |
| cipher_salt1 = 'some-random-salt-' | |
| cipher_salt2 = 'another-random-salt-' | |
| cipher = OpenSSL::Cipher.new('AES-128-ECB').encrypt | |
| cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(cipher_salt1, cipher_salt2, 20_000, cipher.key_len) | |
| encrypted = cipher.update(str) + cipher.final | |
| encrypted.unpack('H*')[0].upcase | |
| end |
| from collections import defaultdict | |
| class Graph: | |
| def __init__(self, start, end): | |
| self.nodes = set() | |
| self.edges = defaultdict(list) | |
| self.distances = {} | |
| self.start = start | |
| self.end = end | |
| def add_node(self, value): |
| <script> | |
| function printDiv(divName){ | |
| var printContents = document.getElementById(divName).innerHTML; | |
| var originalContents = document.body.innerHTML; | |
| document.body.innerHTML = printContents; | |
| window.print(); | |
| document.body.innerHTML = originalContents; |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| function pullJSON() { | |
| var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
| var sheets = ss.getSheets(); | |
| var sheet = ss.getActiveSheet(); | |
| var url="http://example.com/feeds?type=json"; // Paste your JSON URL here | |
| var response = UrlFetchApp.fetch(url); // get feed | |
| var dataAll = JSON.parse(response.getContentText()); // |
| import pyaudio | |
| import wave | |
| FORMAT = pyaudio.paInt16 | |
| CHANNELS = 2 | |
| RATE = 44100 | |
| CHUNK = 1024 | |
| RECORD_SECONDS = 5 | |
| WAVE_OUTPUT_FILENAME = "file.wav" | |
| # More robust version to update new or existing counter cache columns in your Rails app. | |
| # See: https://gist.github.com/svyatov/4225663 | |
| desc 'Update all cache counters' | |
| task :update_cache_counters => :environment do | |
| models_to_update = {} | |
| # or: Rails.application.eager_load! | |
| # Dir loads less, so it's faster | |
| Dir.glob(Rails.root.join('app/models/**/*')).each { |model| require model if File.file?(model) } |
| #!/usr/bin/env ruby -w | |
| # SETUP: | |
| # (assumes ~/bin/ is in your path) | |
| # cp colorize.rb ~/bin/colorize | |
| # chmod +x ~/bin/colorize | |
| # USAGE: | |
| # tail -f log/development.log | colorize | |
| class String |
Rails flash messages with AJAX requests