Skip to content

Instantly share code, notes, and snippets.

View ChandanChainani's full-sized avatar

ChandanChainani

View GitHub Profile
@ChandanChainani
ChandanChainani / ruby_override_new.rb
Created April 8, 2023 02:53 — forked from Integralist/ruby_override_new.rb
Ruby: override `new` constructor method using meta programming
module Bar
module ClassMethods
# `new` is a class method on the `Class` object
# It then uses `send` to access `initialize` which would otherwise be a private instance method
# So it can be overridden by extending the your class with a new `new` class method
def new(*args, &block)
super
p "new constructor defined"
end
end
@ChandanChainani
ChandanChainani / .pryrc
Created February 26, 2023 18:30 — forked from devonzuegel/.pryrc
My .pryrc file
# === EDITOR ===
Pry.editor = 'vi'
require 'awesome_print'
# == Pry-Nav - Using pry as a debugger ==
Pry.commands.alias_command 'c', 'continue' rescue nil
Pry.commands.alias_command 's', 'step' rescue nil
Pry.commands.alias_command 'n', 'next' rescue nil
# === CUSTOM PROMPT ===

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

//Authorization popup window code
function ShowAuthWindow(options)
{
console.log('ee');
options.windowName = options.windowName || 'ConnectWithOAuth'; // should not include space for IE
options.windowOptions = options.windowOptions || 'location=0,status=0,width=800,height=400';
options.callback = options.callback || function(){ window.location.reload(); };
var that = this;
console.log(options.path);
that._oauthWindow = window.open(options.path, options.windowName, options.windowOptions);
@ChandanChainani
ChandanChainani / string-conversion.rs
Created February 24, 2023 07:31 — forked from jimmychu0807/string-conversion.rs
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@ChandanChainani
ChandanChainani / rspec_rails_cheetsheet.rb
Created February 20, 2023 17:24 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@ChandanChainani
ChandanChainani / dsu.js
Created February 19, 2023 16:42 — forked from KSoto/dsu.js
Disjoint Set Union (DSU) with Union Find in Javascript
// https://www.youtube.com/watch?v=wU6udHRIkcc
/*
Disjoint Set Union (“DSU”) is the Data Structure: disjoint-set data structure
is a data structure that keeps track of a set of elements partitioned into a
number of disjoint (non-overlapping) subsets.
Union Find is the Algorithm: A union-find algorithm is an algorithm that can
be used to detect cycles in an undirected graph & performs two useful operations
on such a data structure:
@ChandanChainani
ChandanChainani / private_fork.md
Created November 20, 2022 06:47 — forked from 0xjac/private_fork.md
Create a private fork of a public repository

The repository for the assignment is public and Github does not allow the creation of private forks for public repositories.

The correct way of creating a private frok by duplicating the repo is documented here.

For this assignment the commands are:

  1. Create a bare clone of the repository. (This is temporary and will be removed so just do it wherever.)

git clone --bare git@github.com:usi-systems/easytrace.git

@ChandanChainani
ChandanChainani / azure-key-credentials.py
Created November 3, 2022 07:16 — forked from jcfrank/azure-key-credentials.py
Python script to print out information to configure an Azure app's keyCredentials entry.
#!/usr/bin/env python3
import os
import sys
from base64 import b64encode
from uuid import uuid4
try:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
@ChandanChainani
ChandanChainani / erlang-websocket-sample.md
Created November 3, 2022 07:15 — forked from jcfrank/erlang-websocket-sample.md
A simple erlang cowboy websocket app

Simple Cowboy websocket app

Cowboy is such a simple web framework.
This is a sample websocket app.

new project

Use erlang.mk. Not that you have to, but it'd make things a bit easier.
First, create a folder for project, ex. myproject.
$ cd myproject/