Skip to content

Instantly share code, notes, and snippets.

View amcooper's full-sized avatar
🐖
🐖

Adam Cooper amcooper

🐖
🐖
View GitHub Profile
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@jeetsukumaran
jeetsukumaran / loghistory.sh
Created March 26, 2012 04:03
Track Working Directory as Well as Commands in Shell History
_loghistory() {
# Detailed history log of shell activities, including time stamps, working directory etc.
#
# Based on 'hcmnt' by Dennis Williamson - 2009-06-05 - updated 2009-06-19
# (http://stackoverflow.com/questions/945288/saving-current-directory-to-bash-history)
#
# Add this function to your '~/.bashrc':
#
# Set the bash variable PROMPT_COMMAND to the name of this function and include
@2xyo
2xyo / Python_Rest_API
Created May 24, 2012 06:32
Simple REST API in Python
#!/usr/bin/python
import json
import bottle
from bottle import static_file, route, run, request, abort, response
import simplejson
import pymongo
from pymongo import Connection
import datetime
@discomplex
discomplex / conky-horizontal-bottom2
Last active December 17, 2020 14:24
CONKY CONFIG FILE [Horizontal / Bottom 2]
# Conky CONFIG FILE [Horizontal / Bottom 2]
# Used alongside panel with systray (tint2, xfce4-panel, lxpanel...)
background no
use_xft yes
xftfont Liberation Sans:size=8
update_interval 3.0
total_run_times 0
own_window_argb_visual
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active June 4, 2024 04:16
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

@ma2shita
ma2shita / extend-sinatra-app-skelton-db.diff
Created December 1, 2014 09:24
Extend Sinatra-App-Skelton for using DB(PostgreSQL)
diff --git Gemfile Gemfile
index a531c7c..2932ed2 100644
--- Gemfile
+++ Gemfile
@@ -4,6 +4,11 @@ gem "sinatra"
gem "grape"
gem "slim"
gem "sass"
+gem "activerecord"
+gem "sinatra-activerecord"
@mpas
mpas / gist:58497115057068f15751
Last active November 2, 2023 06:58
Groovy script to convert Csv to Json
import groovy.json.JsonOutput
/**
* A simple CSV file to Json converter
*
* The CSV file is expected to have a header row to identify the columns. These
* columns will be used to generate the corresponding Json field.
*
* @author Marco Pas
*/
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
function f() {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1
@taion
taion / registry.js
Last active May 7, 2019 21:48
Relay type registry
import decamelize from 'decamelize';
import { fromGlobalId } from 'graphql-relay';
import pluralize from 'pluralize';
import getItem from '../api/getItem';
const types = {};
const endpoints = {};
const getItemOverrides = {};