Skip to content

Instantly share code, notes, and snippets.

View jrunning's full-sized avatar

Jordan Running jrunning

View GitHub Profile
@calebdwilliams
calebdwilliams / mixin-annotated.js
Created July 15, 2020 14:17
Mixin annotation with JSDoc and TypeScript
import { LitElement } from 'https://cdn.pika.dev/lit-element@^2.3.1';
/** @typedef {new (...args: any[]) => any} Constructor */
/**
* @template {!Constructor} T
* @param {T} superclass - The class to extend
*/
const FormControlMixin = (superclass) =>
class FormControl extends superclass {
@mpepping
mpepping / token.applescript
Created April 6, 2019 12:20
AppleScript to copy a Safenet MobilePASS OTP
-- AppleScript to copy a Safenet MobilePASS OTP.
--
-- 'osascript ~/path/to/token.applescript'
-- Set 'passwd' to your MobilePASS passcode.
set passwd to "0000"
-- Start MobilePASS
tell application "MobilePASS"
activate
delay 1
-- Apple Script to connect VPN Client with Password and Safenet MobilePass OTP.
set vpn_name to "'VPN Connection 01'"
set user_name to "username"
set passwd to "Password"
tell application "MobilePASS"
activate
end tell
tell application "System Events"
@idettman
idettman / add-to-existing-namespaces.js
Last active July 19, 2024 05:44
JavaScript: JSDoc Advanced Tips
/* https://leahayes.wordpress.com/2011/08/28/documenting-javascript-with-jsdoc3/
Namespaces can still be documented when a more abstract mechanism is used. @lends allows members to be added to an existing namespace:
*/
/**
* Root namespace
* @namespace root
*/
$namespace('root', /** @lends root **/ {
/**
# https://minhajuddin.com/2016/03/03/put-this-in-your-code-to-debug-anything
require 'rouge'
require 'method_source'
require 'pp'
class Dbg
def initialize(object, to:)
@object, @stream = object, to
end
@bterlson
bterlson / mod.js
Last active January 26, 2017 15:25
Module export forms have subtle differences
// exporter1.js
let foo = 1;
export { foo as default }; // exports the foo binding
foo = 2;
// exporter2.js
let foo = 1;
export default foo; // creates a new binding named *default* and initializes it to 1.
foo = 2; // assigns to the foo binding which is not exported
@fredrick
fredrick / App-example-test.js
Last active April 6, 2018 12:39
React Router Test Context Helper
var React = require('react/addons'),
TestUtils = React.addons.TestUtils,
TestContext = require('./TestContext'),
App = require('./App.jsx'),
app = TestContext.getRouterComponent(App);
describe('App', function() {
it('has something', function() {
expect(app.getDOMNode().textContent).toContain('something');
});
@jrunning
jrunning / fun_with_to_proc.rb
Last active August 29, 2015 14:07
Fun with to_proc
class Regexp
def to_proc
proc {|str| match(str) && $~.to_s }
end
end
arr = [ "foo", "bar 123", "baz", "456", "789 qux" ]
p arr.find(&/bar/) # => "bar 123"
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@jrunning
jrunning / server.rb
Created June 30, 2014 18:10
Instant Ruby CGI server
#!/usr/bin/env ruby
require "webrick"
server = WEBrick::HTTPServer.new(Port: 8080, DocumentRoot: Dir::pwd)
trap("INT") { server.shutdown }
server.start