Skip to content

Instantly share code, notes, and snippets.

View nordringrayhide's full-sized avatar

Nodrin Grayhide nordringrayhide

  • home
  • Worldwide
View GitHub Profile
@nordringrayhide
nordringrayhide / state.js
Created August 20, 2023 20:49 — forked from dbisso/state.js
Simple state management in vanilla JS
function State() {
this.actions = {};
this.subscriptions = [];
this.history = [];
}
State.prototype.subscribe = function(element, action, callback) {
this.subscriptions[action] = this.subscriptions[action] || [];
this.subscriptions[action].push(function(data) {
callback.apply(element, data);
@nordringrayhide
nordringrayhide / .envrc
Created June 4, 2021 04:20 — forked from gudleik/.envrc
Node.js direnv setup
# Either use node version specified in package.json
use node package.json
# Or a specific version
use node 5.0.0
# Rest of direnv setup..
export FOO=BAR
@nordringrayhide
nordringrayhide / 1_server-stats-json.sh
Created February 17, 2018 18:15 — forked from walm/1_server-stats-json.sh
Simple Linux Server stats as JSON
#!/bin/sh
echo -n '{'
# memory as "mem": { "current": 800, "total": 1024, "load", 82 } where amount is in MB and load in %
free -m | awk 'NR==2{printf "\"mem\": { \"current\":%d, \"total\":%d, \"load\": %.2f }", $3,$2,$3*100/$2 }'
echo -n ','
# diska as "disk": { "current": 6, "total": 40, "used": 19 } where amount is in GB and used in %
df -h | awk '$NF=="/"{printf "\"disk\": { \"current\":%d, \"total\":%d, \"used\": %d }", $3,$2,$5}'
@nordringrayhide
nordringrayhide / GoogleAuthenticationCurl.sh
Created February 5, 2018 11:27 — forked from LindaLawton/GoogleAuthenticationCurl.sh
Curl bash script for getting a Google Oauth2 Access token
# Client id from Google Developer console
# Client Secret from Google Developer console
# Scope this is a space seprated list of the scopes of access you are requesting.
# Authorization link. Place this in a browser and copy the code that is returned after you accept the scopes.
https://accounts.google.com/o/oauth2/auth?client_id=[Application Client Id]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=[Scopes]&response_type=code
# Exchange Authorization code for an access token and a refresh token.
curl \
@nordringrayhide
nordringrayhide / pg_stat_statements
Created February 28, 2017 14:35 — forked from troyk/pg_stat_statements
enable postgres pg_stat_statements
1) see re: increasing shmmax http://stackoverflow.com/a/10629164/1283020
2) add to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
136 pg_stat_statements.max = 1000
137 pg_stat_statements.track = all
3) restart postgres
4) check it out in psql
@nordringrayhide
nordringrayhide / db.rake
Last active September 3, 2015 19:11 — forked from robertsosinski/db.rake
Database rake tasks for Sequel
namespace :db do
desc "Migrates the database to the target version, or to the lastest version if no target is given"
task :migrate, [:target, :current] => :environment do |t, args|
opts = {}
opts[:target] = args[:target].to_i if args[:target]
opts[:current] = args[:current].to_i if args[:current]
Sequel::Migrator.run(DB, "db/migrate", opts)
Rake::Task["db:dump"].invoke if Rails.env.development?
end
#!/bin/bash
# Based on the "Shell image viewer" by Andreas Schönfelder:
# https://bbs.archlinux.org/viewtopic.php?id=106089
# Defaults.
doublexres="yes"
colors="$(tput colors)"
size="$(($(tput cols) - 2))x$(($(tput lines) - 2))"
@nordringrayhide
nordringrayhide / application.rb
Last active August 29, 2015 14:26 — forked from finack/application.rb
Example Chef Deploy Revision for Rails 3+
app = node[:rails][:app]
rails_base app[:name] do
ruby_ver app[:ruby_ver]
gemset app[:gemset]
end
%w{config log pids cached-copy bundle system}.each do |dir|
directory "#{app[:app_root]}/shared/#{dir}" do
owner app[:deploy_user]

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@nordringrayhide
nordringrayhide / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console