Skip to content

Instantly share code, notes, and snippets.

View servel333's full-sized avatar

Nathaniel Perry servel333

View GitHub Profile
@servel333
servel333 / JsUtils.js
Created September 20, 2013 17:14
A collection of simple JavaScript utilities.
////////////////////////////////////////////////////////////////////////////////
// Type utils
var is_object = function(o) { return o !== null && typeof o === 'object'; };
var is_number = function(o) { return !isNaN(parseFloat(o)) && isFinite(o); };
var is_string = function(o) { return typeof o === 'string'; };
var is_regexp = function(o) { return Object.prototype.toString.call( o ) === '[object RegExp]'; };
var is_regexp_duck = function(o) { return !!(o && o.test && o.exec && (o.ignoreCase || o.ignoreCase === false)); };
var get_internal_type = function(o) { return Object.prototype.toString.call(o).slice(8, -1); };
@servel333
servel333 / applyDirect.js
Created September 20, 2013 17:33
A hacky alternative to function.apply and function.call in cases where those will not work.
(function(window, undefined) {
"use strict";
// @function func.apply( thisArg [, argsArray ] )
// @function func.call ( thisArg [, arg1 [, arg2 [, ...] ] ] )
var _applyIndirect = function(func, thisArg, argsArray) {
Function.prototype.apply.call(func, thisArg, argsArray);
};
@servel333
servel333 / $Array.js
Last active December 23, 2015 13:19
A method of extending the Array class without polluting the global namespace.
// http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
(function(window, undefined) {
"use strict";
var _extend = function() {
var a = [ ];
args = Array.prototype.slice.call(arguments);
a.push.apply(a, args);
@servel333
servel333 / make-npp-workspace.rb
Created September 20, 2013 19:39
Small Ruby script to generate a Notepad++ workspace from a path recursively.
# this.rb c:/path/to/scan > npp.workspace.xml
def puts(*args)
Kernel.puts *args
end
def scan_path(parent, indent='')
paths = Dir.glob(File.join(parent, '*'))
paths.select{ |path| !File.directory? path }.sort.each do |file|
@servel333
servel333 / wget.rb
Last active July 30, 2022 14:26
Basic Ruby implementation of wget to fetch a file from the internet.
def wget(url,file)
require 'net/http'
require 'uri'
if (!file)
file = File.basename(url)
end
url = URI.parse(url)
Net::HTTP.start(url.host) do |http|
@servel333
servel333 / signtool.rb
Created September 20, 2013 19:45
A Ruby wrapper around signtool.exe in order to determine if a Windows file is digitally signed.
def require_signature(file)
abort file+' is not signed!' if !SignTool.is_signed file
end
def warn_if_not_signed(file)
puts '---- WARNING ---- '+file+' is not signed!' if !SignTool.is_signed file
end
class SignTool
@servel333
servel333 / TarmaInstallMate.gitignore
Created November 12, 2013 19:00
Git .gitignore file for Tarma InstallMate.
# Workspace files
*.iw7
*.iw9
# Build log files
*.log
@servel333
servel333 / git-config.sh
Last active September 26, 2022 21:24
Nate's custom git log. One line, graphed, colored, with hash, branches, time, author and description.
## Normal git log
git log -3
# commit 58c7c712ad122bb4739a761d71684dcb23364831
# Author: Nathan Perry <nateperry333@gmail.com>
# Date: Wed Mar 19 22:10:39 2014 -0400
#
# Update README.md
#
# commit cd3137dad3d7debd622885445e0d117246b65603
@servel333
servel333 / BuilderConfig.rb
Created July 8, 2014 18:14
Dynamic builder config
require 'docile'
require 'linguistics'
Linguistics.use :en
class BuilderConfig
def initialize
@paths = @@paths
@versions = @@versions
@servel333
servel333 / db_seeds.rb
Last active March 1, 2024 21:13
Rails seeds for environments
## db/seeds.rb
['all', Rails.env].each do |seed|
seed_file = Rails.root.join('db', 'seeds', "#{seed}.rb")
if File.exists?(seed_file)
puts "*** Loading #{seed} seed data"
require seed_file
end
seed_dir = Rails.root.join('db', 'seeds', seed)