Skip to content

Instantly share code, notes, and snippets.

@bvsatyaram
bvsatyaram / ubuntu-1804-setup.md
Last active July 9, 2020 00:06
Ubuntu 18.04 Setup

Basics

Update and upgrade

sudo apt update
sudo apt -y upgrade
sudo apt install -y vim

Setup Git

Install git

@bvsatyaram
bvsatyaram / linkedList.ts
Created November 8, 2016 11:35
LinkedList.ts
import LinkedListNode from './linkedListNode';
export default class LinkedList {
private headSentinel;
constructor() {
this.headSentinel = new LinkedListNode(null);
}
head() {
@bvsatyaram
bvsatyaram / app.js
Created October 29, 2015 10:39
Simple Hang Man Game
angular.module('Hangman', []);
angular.module('Hangman')
.controller('GameCtrl', function() {
var game = this;
game.word = "SINGLETON";
game.allChars = game.word.split("");
game.chars = [];
angular.forEach(game.allChars, function(char) {
game.chars.push({
@bvsatyaram
bvsatyaram / grid_search.rb
Created October 2, 2015 07:32
Hacker Rank Problem: Grid Search
def check_sub_pattern?(big_grid, small_grid)
big_r = big_grid.length
small_r = small_grid.length
big_c = big_grid[0].length
small_c = small_grid[0].length
(0..(big_r-small_r)).each do |r|
(0..(big_c-small_c)).each do |c|
pattern_found = true
(0...small_r).each do |i|
break if !pattern_found
@bvsatyaram
bvsatyaram / deep-equal.js
Created May 27, 2015 10:12
JS Deep Equal Objects
function deepEqualObjects(a,b) {
for(var prop in a) {
if(!deepEqual(a[prop],b[prop])) {
return false;
}
}
for(var prop in b) {
if(!deepEqual(a[prop],b[prop])) {
return false;
}
function arrayToList(arr) {
var list = null;
for(var i = arr.length -1; i >= 0; i--) {
list = {
value: arr[i],
rest: list
};
}
return list;
@bvsatyaram
bvsatyaram / _form.html.erb
Created February 19, 2015 13:33
Simple Form Example
<%= simple_form_for @new_message, remote: true, html: {class: "form-inline"} do |f| %>
<%= f.input :note, label: false, placeholder: "Enter Message", input_html: { id: "note_input" } %>
<%= f.input :owner_id, as: :hidden %>
<%= f.submit 'Submit', hidden: true %>
<% end %>
@bvsatyaram
bvsatyaram / access_denied.js.erb
Created January 24, 2015 06:31
Authorize Admin for certain actions
$('.flash_messages').html('<%= j flash_tag("Access Denied!", "alert") %>')
@bvsatyaram
bvsatyaram / Messaging System
Last active December 27, 2015 14:28
Messaging System
This gist tries to give an example of how to build a simple, yet robust, messaging system.
We assume that the users are handed by `User` model.
The following models are proposed:
Conversation::Thread
Conversation::ThreadSubscription
Conversation::Message
Conversation::MessageSubscription
/**
* Add dataset support to elements
* No globals, no overriding prototype with non-standard methods,
* handles CamelCase properly, attempts to use standard
* Object.defineProperty() (and Function bind()) methods,
* falls back to native implementation when existing
* Inspired by http://code.eligrey.com/html5/dataset/
* (via https://github.com/adalgiso/html5-dataset/blob/master/html5-dataset.js )
* Depends on Function.bind and Object.defineProperty/Object.getOwnPropertyDescriptor (shims below)
* Licensed under the X11/MIT License