Skip to content

Instantly share code, notes, and snippets.

Avatar

scaryguy

  • Silicon Valley
View GitHub Profile
@scaryguy
scaryguy / two_pointers.js
Created Nov 30, 2018
Two Pointers Technique (in JavaScript)
View two_pointers.js
// 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 / window_sliding_in_javascript.js
Created Nov 29, 2018
Window Sliding Technique in JavaScript
View window_sliding_in_javascript.js
// 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
View gist:6ec840c2896a35688530e185ab9a99b1
{ "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.",
@scaryguy
scaryguy / change_primary_key.md
Last active Mar 1, 2021
How to change PRIMARY KEY of an existing PostgreSQL table?
View change_primary_key.md
-- 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 / change_id_column
Last active Oct 17, 2020
How to reset ID column of a PostgreSQL table to let auto incrementation begin from 1?
View change_id_column
# 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');