Skip to content

Instantly share code, notes, and snippets.

View maletor's full-sized avatar

Ellis Berner maletor

View GitHub Profile
@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 / 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).
@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
@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 / 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,
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
paperclip (~> 5.1.0) was resolved to 5.1.0, which depends on
activemodel (>= 4.2.0) was resolved to 5.0.0.1, which depends on
activesupport (= 5.0.0.1)
friendly_id (~> 5.1.0) was resolved to 5.1.0, which depends on
activerecord (>= 4.0.0) was resolved to 4.2.7.1, which depends on
activesupport (= 4.2.7.1)
@maletor
maletor / mutual.sql
Last active September 22, 2016 16:25
Query mutual friends through joining the friendships table twice
SELECT `users`.* FROM `users`
INNER JOIN `friendships` `a` ON `users`.`id` = `a`.`friend_id`
INNER JOIN `friendships` `b` ON `users`.`id` = `b`.`friend_id`
WHERE `a`.`user_id` = 1 AND `b`.`user_id` = 2
<input value={{newEmail}}
oninput={{action (action updateEmail) value="target.value"}} />
// app/services/invite.js
recommendationsFromStore: Ember.computed(function(){
return this.get('store').findAll('pymkRecommendation');
}),