Skip to content

Instantly share code, notes, and snippets.

View radiosilence's full-sized avatar
🔥

James Cleveland radiosilence

🔥
View GitHub Profile
@radiosilence
radiosilence / example.ts
Last active April 21, 2017 13:09
I am having a confuse about generics
interface Z {
potato: string
}
abstract class A<T> { // I want to indicate that T will always at least implement Z
protected foo(bar: T) {
console.log(bar.potato); // ERROR: [ts] Property 'potato' does not exist on type 'T'
}
}
@radiosilence
radiosilence / utils.js
Created November 17, 2014 11:32
Handy function to turning a nested object into a list of string based constants.
"use strict";
module.exports = {
constantify: function constantify(app, obj, prevK) {
for (var k in obj) {
var nextK = prevK ? prevK + '.' + k : app + '.' + k;
if (obj[k] === null) obj[k] = nextK;
else constantify(app, obj[k], nextK);
}
return obj;
@radiosilence
radiosilence / gist:b65b268e74b24f0ffc79
Created September 18, 2014 11:56
fucking around with mori
Download the React DevTools for a better development experience: http://fb.me/react-devtools react.js:4356
DOM fully loaded and parsed uitest.html:40
You are using the in-browser JSX transformer. Be sure to precompile your JSX for production - http://facebook.github.io/react/docs/tooling-integration.html#jsx JSXTransformer.js:12703
_
function (obj) {
if (obj instanceof _) return obj;
if (!(this instanceof _)) return new _(obj);
this._wrapped = obj;
} underscore.js:36
mori
@radiosilence
radiosilence / index.html
Last active August 29, 2015 14:00
Versioned repository pattern for JS
<!doctype html>
<html>
<head>
</head>
<body>
<div id="main" />
<script src=http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js></script>
<script src=http://cdnjs.cloudflare.com/ajax/libs/react/0.10.0/JSXTransformer.js></script>
<script src=http://cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react-with-addons.min.js></script>
<script type="text/jsx">
@radiosilence
radiosilence / comments.json
Created January 14, 2014 17:04
Shitty first attempt at something with React.
[{"author":"Barry Smith","text":"Test"},{"author":"James Brown","text":"ASDFG!"}]
[{"author":"Barry Smith","text":"Test"},{"author":"James Brown","text":"ASDFG!"}]
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.0.3/cosmo/bootstrap.min.css">
</head>
<body>
<div id="container" class="container">
</div>
<script asrc="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script asrc="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.0.3/cosmo/bootstrap.min.css">
</head>
<body>
<div id="container" class="container">
</div>
<script asrc="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script asrc="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
@radiosilence
radiosilence / beautiful.sql
Last active August 14, 2016 11:16
Django Raw Annotations. I wanted to add some complex aggregates, but .extra(select=) adds your raw SQL to GROUP BY, which doesn't work for aggregates. So, I trick the annotate() function by creating my own class that pretends to be an aggregate, but really just dumps SQL. Do not use for user inputted data.
SELECT "businesses_business"."id", "businesses_business"."user_id", "businesses_business"."slug", "businesses_business"."name", "businesses_business"."business_type_id", "businesses_business"."street", "businesses_business"."additional", "businesses_business"."town", "businesses_business"."county", "businesses_business"."postcode_id", "businesses_business"."phone_number", "businesses_business"."fax_number", "businesses_business"."email", "businesses_business"."website", "businesses_business"."strapline", "businesses_business"."description", "businesses_business"."active", "businesses_business"."deleted", "businesses_business"."activation_code", "businesses_business"."created_on", "businesses_business"."account_confirmed", "businesses_business"."preview", "businesses_business"."paid", "businesses_business"."last_updated", "businesses_business"."copy_id", "businesses_business"."logo", "businesses_business"."security_reference", "businesses_business"."video", "businesses_business"."embed_url", "businesses_busine
http = require 'http'
pg = require('pg').native
Promise = require 'bluebird'
reportError = (res, err, chains) ->
res.writeHead 500,
'content-type': 'application/json'
res.write JSON.stringify err