Skip to content

Instantly share code, notes, and snippets.

@scaryguy
scaryguy / change_primary_key.md
Last active April 8, 2024 14:23
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@scaryguy
scaryguy / window_sliding_in_javascript.js
Created November 29, 2018 16:20
Window Sliding Technique in JavaScript
// This gist is for my YouTube video which I tried to explain Window Sliding Technique.
// You can watch it from here: https://youtu.be/ZlnZkfEcbxs
//
// Given an array of integers of size ‘n’. Calculate the maximum sum possible
// for ‘k’ consecutive elements in the array.
//
// Input : [10, 20, 30, 40, 50, 60, 70]
//
// k = 3
// Output : 180
@scaryguy
scaryguy / two_pointers.js
Created November 30, 2018 14:47
Two Pointers Technique (in JavaScript)
// This gist is for my YouTube video which I tried to explain Window Sliding Technique.
// You can watch it from here: https://youtu.be/guDU5HnLqAs
// Given a sorted array A (sorted in ascending order), having N integers,
// find if there exists any pair of elements (A[i], A[j]) such that
// their sum is equal to X.
//
// Input: A = [2,3,4,5,6,7,8,9], k= 10
// Output: true
// NOTE: We slightly changed the question and the output in the video. We're returning pair indexes as an array.
@scaryguy
scaryguy / change_id_column
Last active March 21, 2022 15:24
How to reset ID column of a PostgreSQL table to let auto incrementation begin from 1?
# See your sequence name inside psql console with \ds command.
ALTER SEQUENCE seq RESTART WITH 1;
# Update sequence
UPDATE table_name SET id=nextval('seq');
{ "speakers": [
{ "firstname": "Ray",
"lastname": "Villalobos",
"category": "Front End",
"title": "Bootstrap & CSS Preprocessors",
"images": [{"one": "http://images1.luckygamez.com/eleminiscard.jpg"},
{"two": "http://barcampdeland.org/images/speaker_rayvillalobos.jpg"},
{"three": "http://barcampdeland.org/images/speaker_rayvillalobos.jpg"}],
"link": "http://iviewsource.com",
"bio": "Ray Villalobos is a full-time author and teacher at lynda.com. He is author of the book, Exploring Multimedia for Designers. He has more than 20 years experience in developing and programming multimedia projects. Previously at Entravision Communications, he designed and developed a network of radio station and TV web sites. As a senior producer for Tribune Interactive, he was responsible for designing orlandosentinel.com and for creating immersive multimedia projects and Flash games for the site.",