Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
remarkablemark / spy-resize-event.test.js
Created June 13, 2018 19:20
How to spy on window resize event in test.
const spy = jest.fn(); // or `jasmine.createSpy()`
const testWidth = 420;
beforeAll(() => {
window.addEventListener('resize', spy);
});
it('does not fire resize event by default', () => {
expect(spy).not.toHaveBeenCalled();
expect(window.innerWidth).not.toBe(testWidth);
@henriquemenezes
henriquemenezes / postgresql-set-id-seq.sql
Created March 31, 2016 12:23
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@rob-murray
rob-murray / find_dups.rb
Created October 27, 2015 09:59
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)