Skip to content

Instantly share code, notes, and snippets.

**Routes**
resources :books do
get 'search', :on => :collection
end
**Forms**
<%= form_with(model: book, local: true) do |form| %>
<%= label_tag(:name, "Name:") %>
<%= form.text_field :name %>
<%= label_tag(:description, "Description:") %>
@cheynewallace
cheynewallace / nginx-ssl-wordpress-letsencrypt
Last active June 28, 2018 11:51
Nginx Site Running WordPress SSL Config Using LetsEncrypt Cert
server {
listen 80;
server_name yoursite.com www.yoursite.com;
return 301 https://www.yoursite.com$request_uri;
}
# HTTPS server
server {
listen 443;
server_name www.yoursite.com yoursite.com;
@cheynewallace
cheynewallace / asana_unicorns.js
Created May 13, 2015 23:02
Infinite Asana Unicorns
setInterval(function(){
env.dynamic_loader.load({url:CommonUrl.staticUrl({path:"apps/asana/view/asana_rainbow.js", compute_hash:!1}), allow_cached:!1 , callback:function(a, b) {
b && AsanaRainbow.start()
}})},1000)
@cheynewallace
cheynewallace / unicorn
Last active August 29, 2015 14:06
Run Rails Unicorn Server As Ubuntu Service
# Add this line to your web app users crontab to start unicorn after reboot
@reboot service unicorn start
@cheynewallace
cheynewallace / dns_export.bat
Created April 1, 2014 23:27
Export DNS Zone As Text File Info To %windir%\System32\dns. Takes single zone name as parameter
@ECHO OFF
REM Run this with: dns_export.bat <your_zone_name>
ECHO ###############################
ECHO ## REMOVING OLD ZONE EXPORT ##
ECHO ###############################
del C:\Windows\System32\dns\%1.txt
ECHO
ECHO ###########################################
ECHO ## EXPORTING %1 ZONE DNS CONFIGURATION ##
ECHO ###########################################
@cheynewallace
cheynewallace / ExportSchema.ps1
Last active March 21, 2024 07:08
Export MSSQL schema with PowerShell. This script will export your schema definitions for tables, stored procs, triggers, functions and views to .sql files
# Usage: powershell ExportSchema.ps1 "SERVERNAME" "DATABASE" "C:\<YourOutputPath>"
# Start Script
Set-ExecutionPolicy RemoteSigned
# Set-ExecutionPolicy -ExecutionPolicy:Unrestricted -Scope:LocalMachine
function GenerateDBScript([string]$serverName, [string]$dbname, [string]$scriptpath)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
@cheynewallace
cheynewallace / mysql_create_db_user_grant.sql
Last active January 24, 2021 16:51
Simple script using prepared statements to create a MySQL database, with user that has same name as the database, then grant the user full permissions on the database. Simply change the two variable assignments at the top
# Only change these two variables.
# DATABASENAME is used for both the database name and username
SET @DATABASENAME = "service_abc";
SET @USERPASSWORD = "password123";
# ======== PERFORM =========
# Drop Database If Exists
SET @DROP_DB = concat("DROP DATABASE IF EXISTS ",@DATABASENAME);
@cheynewallace
cheynewallace / NetStatPortsAndProcessNames.cs
Last active March 31, 2024 18:53
C# Get Active Ports and Associated Process Names. This code will parse the output from a "netstat -a -n -o" and retrieve a list of active listening ports, along with the associated PID. The PID is then resolved to a process name so we can see exactly which port is attached to which process.
// ===============================================
// The Method That Parses The NetStat Output
// And Returns A List Of Port Objects
// ===============================================
public static List<Port> GetNetStatPorts()
{
var Ports = new List<Port>();
try {
using (Process p = new Process()) {
@cheynewallace
cheynewallace / ga-event-tracker.js
Last active October 18, 2018 12:14
jQuery Google Analytics Event Tracking Using HTML Attributes
/*JSHint Options*/
/*global _gaq */
/*
Google Analytics Event Tracking - JSHint Checked
Written By Cheyne Wallace - 19th Nov 2012
Click Usage: <a href="http://somewhere"
class="ga-track"
event_category="Event Category"
event_action="Specific Action"
event_label="Optional Message"