Skip to content

Instantly share code, notes, and snippets.

View foxyblocks's full-sized avatar

Chris Schlensker foxyblocks

View GitHub Profile
@foxyblocks
foxyblocks / javascript.json
Last active February 2, 2021 17:31
Paste this into your vscode javascript user snippets. Activate it by typing 'nim+TAB'. It will focus the path part of the import statement first which will cause autocomplete to work on the named import.
{
"Completeable named import": {
"prefix": ["nim"],
"body": ["import { ${2:value} } from \"${1:path}\";$0"],
"description": "A javascript named import statement that works with autocomplete by making you type the path statement first"
}
}
## Given a glob pattern and a base directory expands that into a list of sass @import statements for files in that directory
glob = ARGV[0]
basedir = ARGV[0]
Dir.chdir(basedir) do
Dir[glob].each do |f|
puts "@import '#{f.gsub(/.scss$/, '')}';"
end
@foxyblocks
foxyblocks / ClickBoundary.jsx
Last active August 4, 2018 22:02
ClickBoundary react component implementation used inside the Bugsnag dashboard.
// Author: Christian Schlensker for Bugsnag.
// @flow
import { omit } from 'lodash';
import * as React from 'react';
// Creates a React context to track track the tree of ClickBoundaries down the component hierarchy.
const NodeContext = React.createContext();
type Props = {
#!/usr/bin/env ruby
ROOT_PATH = File.dirname(__FILE__) + '/js/dashboard/'
COMPONENT_REGEX = /window\.(\w+) =.+(React|Reflux)/
files = Dir.glob(ROOT_PATH + "**/*.{js,jsx,coffee,cjsx}")
# hard coded modules that we want to require. This list will be amended by searching for
# `window.X = (React|Redux)` definitions in the code base
components = [
{name: 'UserActions', import_path: 'user_actions'},
{name: 'UrlService', import_path: 'services/url_service'},
@foxyblocks
foxyblocks / bugsnag.js
Last active August 1, 2016 23:52
A simple isomorphic bugsnag module. (requires that process.env.IS_BROWSER be present in browser build)
// The bugsnag javascript libraries are not isomorphic so we need to specify which one we want to use depending on environment.
let Bugsnag;
if (process.env.IS_BROWSER) {
Bugsnag = require('bugsnag-js');
Bugsnag.apiKey = process.env.MY_BROWSER_PROJECT_API_KEY;
} else {
Bugsnag = require('bugsnag-node');
Bugsnag.register(process.env.MY_NODE_PROJECT_API_KEY);
}
@foxyblocks
foxyblocks / setup.js
Created June 29, 2016 22:21
Automatic angular http error tracking with Bugsnag
angular.module('myApp').config(['$httpProvider', function ($httpProvider) {
var interceptor = ['$q', function ($q) {
function success(response) {
return response;
}
function error(response) {
// Here we decide when and how to notify Bugsnag
if (response.status != 400) { // skip notification for form validation errors
Bugsnag.notify(response.statusText, response.config.url, {response: response})
@foxyblocks
foxyblocks / clock.module.js
Last active April 21, 2016 14:30
Angular JS Analog Clock directive
// Clock Directive
// Demo at http://embed.plnkr.co/W36A8G1dJfmbnXSnbl98/preview
// Uses SVG to render an analog clock
// Requires moment.js and also moment-timezone if you set the `zone` optional attribute.
// Usage
// <clock radius='40'></clock>
// You can also set the timezone
// <clock radius='40' zone='America/New_York'></clock>
module AnimalKingdom
def type
'Animal'
end
end
module PlantKingdom
def type
'Plant'
end
// This is a plugin for ImpactJS that Google Chrome
// rendering for the Macbook Pro with Retina display.
// Based on the solution offered on http://www.html5rocks.com/en/tutorials/canvas/hidpi/
// It probably have a negative impact on performance.
// Use wisely.
//
//
// Place this in lib/plugins/smart-resize.js
@foxyblocks
foxyblocks / gist:5871998
Last active December 19, 2015 00:58
Jquery Key Event mapping
KeyCodes =
K_CANCEL: 3
K_HELP: 6
K_BACK_SPACE: 8
K_TAB: 9
K_CLEAR: 12
K_RETURN: 13
K_ENTER: 14
K_SHIFT: 16
K_CONTROL: 17