Skip to content

Instantly share code, notes, and snippets.

View maletor's full-sized avatar

Ellis Berner maletor

View GitHub Profile
@maletor
maletor / crypto-aes-256-gcm-demo.js
Last active July 14, 2023 06:45 — forked from rjz/crypto-aes-256-gcm-demo.js
example using node.js crypto API with aes-256-gcm
const buffer = require('buffer');
const crypto = require('crypto');
// Demo implementation of using `aes-256-gcm` with node.js's `crypto` lib.
const aes256gcm = (key) => {
const ALGO = 'aes-256-gcm';
// encrypt returns base64-encoded ciphertext
const encrypt = (str, aad) => {
// Hint: the `iv` should be unique (but not necessarily random).
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<%= include_javascripts :maptastic %>
<script type="text/javascript">
$j(window).load(function() {
initializeMap();
<% @pharmacies.each do |pharmacy| -%>
<% unless pharmacy.lat.nil? || pharmacy.lon.nil? -%>
// addMarker(new google.maps.LatLng(<%= pharmacy.lat -%>, <%= pharmacy.lon -%>), '<%= escape_javascript h pharmacy.name -%>', '<%= escape_javascript h pharmacy_info_window(pharmacy) -%>');
<% end -%>
<% end -%>
@maletor
maletor / Ruby and Rails Interview Cheat Sheet.md
Created March 21, 2017 17:32 — forked from ahmadhasankhan/Ruby and Rails Interview Cheat Sheet.md
This is my Ruby interview cheat sheet. Feel free to fork it, Use it, Share it, or do whatever you want with it. PLEASE let me know if there is any error or if anything crucial is missing. I will keep updating...

Ruby and Rails Interview Questions

Ruby

  • What is a class?
  • What is an object?
  • What is a module? Can you tell me the difference between classes and modules?
  • Can you tell me the three levels of method access control for classes and modules? What do they imply about the method?
  • There are three ways to invoke a method in ruby. Can you give me at least two?
  • Explain this ruby idiom: a ||= b
@maletor
maletor / request.ts
Created November 3, 2020 16:21
Generic HTTP methods
import { IncomingMessage } from "http";
import { Agent, request, RequestOptions } from "https";
const agent = new Agent({ keepAlive: true, timeout: 10000 });
class MissingStatusCodeError extends Error {
constructor(public url: string) {
super("Missing a status code");
this.name = "MissingStatusCodeError";
this.url = url;
@maletor
maletor / img_convert.rb
Created October 3, 2011 22:24 — forked from arirusso/img_convert.rb
convert html img tags to rails image_tag calls
#!/usr/bin/env ruby
require "nokogiri"
# opens every file in the given dir tree and converts any html img tags to rails image_tag calls
#
# example usage:
# ruby convert.rb ~/my_rails_app/app/views
#
# ***be careful and backup before using this***
#
@maletor
maletor / enum_perf_small.rb
Last active June 7, 2018 23:08 — forked from taq/enum_perf_small.rb
Ruby 2.0 lazy enumerators small collection performance
require "benchmark"
include Benchmark
values = (0..10_000_000).to_a
bm(1_000_000) do |bench|
bench.report("map and select") do
values.map { |x| x * 3 }.select { |x| x % 4 == 0 }
end
bench.report("inject") do
Table
-----
id msg_id name
1 | 1 | Tom
2 | 1 | Dick
3 | 1 | Harry
4 | 2 | Tom
5 | 2 | Dick
6 | 3 | Tom
annotation
class Annotation < ActiveRecord::Base
belongs_to :image, :class_name => "Comment:Image"
include_root_in_json = false
end
comment
class Comment::Image < Asset
versioned
has_attached_file :attachment, :styles => { :small => "200x150>", :large => "400x300>" }
@maletor
maletor / gist:68f818ad0bbb534004cf4a603ae637d3
Created January 3, 2017 23:03
Mysterious behavior of find_by
(byebug) Survey::Token.find_by(token: params[:token], survey_id: @@survey)
nil
(byebug) Survey::Token.where(token: params[:token], survey_id: @@survey).take
#<Survey::Token id: 49078,
@maletor
maletor / contact_importer.rb
Created September 3, 2014 18:18
Use OAuth to import contacts
require 'oauth'
require 'oauth2'
class ContactImporter
def initialize(importer)
@importer = importer
end
def authorize_url
case @importer