Skip to content

Instantly share code, notes, and snippets.

Avatar

Ellis Berner maletor

View GitHub Profile
@maletor
maletor / request.ts
Created Nov 3, 2020
Generic HTTP methods
View request.ts
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 Aug 12, 2020 — forked from rjz/crypto-aes-256-gcm-demo.js
example using node.js crypto API with aes-256-gcm
View crypto-aes-256-gcm-demo.js
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 Jun 7, 2018 — forked from taq/enum_perf_small.rb
Ruby 2.0 lazy enumerators small collection performance
View enum_perf_small.rb
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
View gist:00304f5f38635d7005285a724f8c96b9
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 Mar 21, 2017 — 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...
View Ruby and Rails Interview Cheat Sheet.md

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
View gist:68f818ad0bbb534004cf4a603ae637d3
(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,
View gist:bae638484376b4ad23be27786fc1ab91
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 Sep 22, 2016
Query mutual friends through joining the friendships table twice
View mutual.sql
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
View child-form.hbs
<input value={{newEmail}}
oninput={{action (action updateEmail) value="target.value"}} />
View invite.js
// app/services/invite.js
recommendationsFromStore: Ember.computed(function(){
return this.get('store').findAll('pymkRecommendation');
}),