Skip to content

Instantly share code, notes, and snippets.

View jeffjohnson9046's full-sized avatar

Jefe Johnson jeffjohnson9046

View GitHub Profile
@jeffjohnson9046
jeffjohnson9046 / devise.rb
Created May 13, 2014 19:02
Bypass LDAP Authentication in Rails When Using Devise
# Add the Warden strategy contained in local_override.rb into the devise.rb file. The devise.rb should also be in the config/intializers directory.
Devise.setup do |config|
config.warden do |manager|
manager.default_strategies(:scope => :user).unshift :local_override
end
# Other devise configuration...
end
@jeffjohnson9046
jeffjohnson9046 / sinatra-server.rb
Last active April 21, 2025 06:08
A simple sinatra server that accepts a POST with JSON content.
# To make this server publicly available on the inter-webs while running from localhost, use ngrok, which can be found here:
# https://ngrok.com/download. Follow the installation instructions for ngrok and start it up:
#
# ./ngrok 4567 # (or whatever port you want to listen on).
#
# ngrok will spit out an ugly but unique URL. After ngrok starts up, you should be able to POST to the sinatra server:
#
# http://6eee766f.ngrok.com/payload
require 'sinatra'
require 'json'
@jeffjohnson9046
jeffjohnson9046 / jquery_jsonp.js
Created August 2, 2014 00:55
jQuery JSONP Request
// This is something I ALWAYS forget about, so hopefully this Gist will serve as a reminder. Whenever you get the "Access-Control-Allow-Origin"
// error, that's because you're trying to make a cross-domain AJAX request, which is a big no-no in the world of the internet.
// So, after spending WAY more time than I care to admit trying to address this, I remembered that JSONP is the answer. Here's
// how to do it:
$.ajax({
url: [/* whatever your URL is */],
/*type: 'GET',*/ // seems superfluous - .ajax uses GET by default.
dataType: 'jsonp',
/*crossDomain: true,*/ // seems to work fine without this.
data: { /* an object with whatever data you need to pass along in your JSONP request */ },
@jeffjohnson9046
jeffjohnson9046 / gist:2c4e35a082bb0abf74db
Last active August 29, 2015 14:05
C# - sort a list by some arbitrary sort order (i.e. not a "typical" sort order).
// You can paste this code into IDEone (http://ideone.com) and run it. For some reason, I can never remember how to do this.
// Therefore, I've made this Gist. There's probably a million smarter ways to handle this situation, but this one seems to
// work just fine.
using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
@jeffjohnson9046
jeffjohnson9046 / valid_json.rb
Created August 24, 2014 15:56
A quick and dirty way to tell if the data received in a response can be parsed as JSON.
def valid_json?(data)
JSON.parse(data)
return true
rescue JSON::ParserError
return false
end
@jeffjohnson9046
jeffjohnson9046 / persistence.xml
Created October 5, 2014 20:22
An example of a Spring MVC persistence.xml file.
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="punit"></persistence-unit>
</persistence>
@jeffjohnson9046
jeffjohnson9046 / cat.sh
Created November 7, 2014 22:28
Sort a List of Files and Cat Them Together
# The command below will take a list of files in the current directory, sort them and cat them together into a single file.
# The files against which this command was initially used were all named using the following convention:
#
# V[some number]__[the name of the file].sql
cat `ls -1 *.sql | sort -k1.2n` > /tmp/migration.sql
@jeffjohnson9046
jeffjohnson9046 / Preferences.sublime-settings
Created January 19, 2015 18:36
My preferences file for the Sublime Text editor.
{
"caret_style": "phase",
"color_scheme": "Packages/Base16 Color Schemes/base16-default.dark.tmTheme",
"fade_fold_buttons": false,
"font_face": "Source Code Pro",
"font_size": 12.0,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
@jeffjohnson9046
jeffjohnson9046 / log4x-config.xml
Created March 13, 2015 19:47
Configure Log4net/Log4j/Log4php Loggers for Each Class
<!-- Configure a Daily File Appender.
-- The datePattern param specifies how the date should appear in the file name.
-- The root element sets the log level for every logger that is configured in this file.
-- To override the log level for an individual logger, add a level element to the desired logger and set it to whatever you want.
-- Each class has its own logger.
-- The name of the logger matches the class exactly.
-- In PHP, this means we can create a logger like this (in a class's constructor, for example):
-- $logger = Logger::getInstance( __CLASS__ );
-->
<configuration xmlns="http://logging.apache.org/log4php/">
@jeffjohnson9046
jeffjohnson9046 / gist:57a17a534c7d4829d0b5
Created March 24, 2015 19:42
Git: Squashing [x] commits into a single commit
# Came from the second answer on here: http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git
# but writing it out myself helps get it through the metal plate in my head.
#
# Assumes the following situation:
# You have a feature branch that you're developing against, e.g. feature/diaper-horse.
# You have a remote branch origin/feature/diaper-horse.
# feature/diaper-horse is set up to track origin/feature/diaper-horse
#
# Let's say you have 8 commits total (of your own) for the branch feature/diaper-horse.
# Reset to x - 1, where x is the number of commits you're ahead of the remote branch. Like so: