Skip to content

Instantly share code, notes, and snippets.

View raineorshine's full-sized avatar

Raine Revere raineorshine

  • New York, NY
View GitHub Profile
@raineorshine
raineorshine / google-analytics-embed.js
Last active May 3, 2019 00:27
Google Analytics example
// 1. basic tracking code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35559116-1']);
_gaq.push(['_setDomainName', 'collegecoding.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
@raineorshine
raineorshine / Web Dev Shell Commands.sh
Last active December 11, 2015 18:39
Common Linux commands that I use when developing web applications.
# stylus compile & watch
stylus public/style/main.styl -w &
npm outdated # nicest way to list installed modules
npm ls # list installed modules & dependencies
npm ls -g # list globally installed node modules
npm update # check for updated versions of modules in the current package
npm view {pkg} # view a package's published metadata
npm install {pkg} --save # install the latest version of a package and add it to your package.json's dependencies
npm install {pkg} --save-dev # install and save as a devDependency
@raineorshine
raineorshine / mongo-cheat-sheet.js
Last active July 7, 2022 20:22
Cheat Sheet: MongoDB
/* COMMAND LINE */
mongod & // start mongo server on port 27017 by default
mongo mydb // launch mongo shell using the specified database
// importing & exporting
mongoimport -d mydb -c mycollection --jsonArray --file input.json
mongoimport -d mydb -c mycollection --headerline --type csv --file input.csv
mongoexport -d mydb -c mycollection --out output.json
/* MONGO SHELL */
@raineorshine
raineorshine / cpp-commands.md
Created March 4, 2013 13:36
Compiler Commands

Compile C++

g++ -Wall hello.cpp -o hello

@raineorshine
raineorshine / ActionListenerDemo.java
Last active December 14, 2015 16:48
Demonstrates how to hook up a function to the 'click' event of a button with addActionListener in a Swing-based Java application
package actionlistenerdemo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// The primary class is a JFrame which can be shown when the program starts
public class ActionListenerDemo extends JFrame {
/* main is just housed inside of the primary class. It creates a new
@raineorshine
raineorshine / cheatsheet-git.sh
Last active December 22, 2023 15:59
Cheatsheet: git commands
# adding and committing
git add -A # stages All
git add . # stages new and modified, without deleted
git add -u # stages modified and deleted, without new
git commit --amend # Add staged changes to previous commit. Do not use if commit has been pushed.
git commit --amend --no-edit # Do so without having to edit the commit message.
# remotes - pushing, pulling, and tracking
git fetch # gets remote objects and refs. Needed if new branches were added on the remote.
git remote -v # Lists all remotes (verbose)
@raineorshine
raineorshine / recursion.java
Last active December 14, 2015 22:18
Java: Simple Recursion Example
public class RecursionTest
{
public static int calc(int n)
{
// base case
if(n == 0)
{
return 1;
}
@raineorshine
raineorshine / loops-objects-vs-arrays.js
Last active December 15, 2015 01:58
Looping over Objects vs Arrays in Javascript (Beginner)
// looping over an array
var fruit = ["Mango", "Guanabana", "Mamoncino", "Piña"];
for(var i=0; i<fruit.length; i++) {
console.log(fruit[i]);
}
// looping over an object
var students = {
// key : value
// access a value with object[key]
@raineorshine
raineorshine / equiv-conditionals.java
Created March 20, 2013 00:37
Logic Practice: Equivalent Conditionals (beginner)
// all three of the below code snippets are equivalent!
// #1: If you notice the body of your 'if' is empty but your else has code, then convert it to #2
if(A && B)
{
// do nothing
}
else
{
doSomething();
@raineorshine
raineorshine / enums-vs-strings.java
Last active December 15, 2015 04:58
Enums vs Strings in Java (Beginner/Intermediate)
/*
Enums are mostly for internal purposes. Think of it as a way to make your job as a developer
easier when you have a few predefined values and you don't want to have to remember obscure codes.
Let's say you have three different states in your program: 0 means INACTIVE, 1 means PENDING, and 2
means ACTIVE.
*/
// You could keep track of the state with an integer like so:
int programState = 1; // PENDING