Skip to content

Instantly share code, notes, and snippets.

class SessionsController < ApplicationController
def create
@user = User.find_or_create_from_auth_hash(env["omniauth.auth"])
session[:user_id] = @user.id
redirect_to :me
end
def destroy
session[:user_id] = nil
@Carpetfizz
Carpetfizz / user.rb
Last active December 30, 2016 01:17
class User < ApplicationRecord
def self.find_or_create_from_auth_hash(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.email = auth.info.email
user.picture = auth.info.image
user.save!
@Carpetfizz
Carpetfizz / CheatCode.js
Last active June 10, 2016 10:46
Listen for characters typed into your website to invoke a function
function CheatCode(){
this._lettersPressed = [];
this._registeredWords = [];
var _getLastN = function(n, a){
var r = [];
for(var i=0; i<n; i++){
r.push(a[a.length - i -1])
}
return r.reverse();
@Carpetfizz
Carpetfizz / leftpad.scm
Created March 25, 2016 02:47
A scheme implementation of the infamous leftpad.js
(define (leftpad s l c)
(if (number? s)
(set! s (number->string s))
)
(if (number? c)
(set! c (number->string c))
)
(define (_leftpad _s _l _c)
(if (<= _l 0)
_s
@Carpetfizz
Carpetfizz / README.md
Last active December 29, 2023 00:42
Craigslist scraper for finding new apartments

Craigslist housing scraper

Still very much a WIP but it gets the job done.

Usage

  1. pip install -r requirements.txt
  2. Replace WATCH_URL and BASE_URL in scraper.py
  3. python3 scraper.py output_file
@Carpetfizz
Carpetfizz / namepicker.js
Created January 15, 2015 02:50
Experimental Design Random Name Picker
var fs = require('fs');
var data = fs.readFileSync('listofnames.txt','utf8').toString().split("\n");
var mainset = []; //Random group of 60 students
var subsetOne = []; //Random group of a subset of 30 / 60 students
var subsetTwo = []; //Random group of a subset of 30 / 60 students
var indicesSetOne = [];
var indicesSetTwo = [];
var indicesSetThree = [];
//Random function with arg max number
@Carpetfizz
Carpetfizz / comments.json
Created November 14, 2014 06:11
Documented ReactJS Tutorial
[
{"author": "Pete Hunt", "text":"This is one comment"},
{"author": "Jordan Walke", "text": "This is another comment"},
{"author": "Elon Musk", "text": "SPAAAAAAAAAACE"}
]