Skip to content

Instantly share code, notes, and snippets.

@jwoertink
jwoertink / sample.js
Created March 15, 2018 02:26
Which style do you prefer for your React Class?
// Sample A. Inline export with implicit import
import React from 'react';
export default class SampleA extends React.Component {
}
// Sample B. Inline export with explicit import
import React, { Component } from 'react';
export default class SampleB extends Component {
}
require "../src/sdl"
require "../src/image"
SDL.init(SDL::Init::VIDEO); at_exit { SDL.quit }
SDL::IMG.init(SDL::IMG::Init::PNG); at_exit { SDL::IMG.quit }
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
window = SDL::Window.new("SDL tutorial", SCREEN_WIDTH, SCREEN_HEIGHT)
require "kemal"
class RequestPathMiddleware < Kemal::Handler
def initialize(@number : String, @use_header : Bool = false)
end
def call(env)
if @use_header
process_request(env)
end
require "kemal"
class AuthorizationHandler < HTTP::Handler
ACCEPT = "application/vnd.api.v1+json"
def call(env)
if env.request.headers["Accept"] != ACCEPT
env.response.status_code = 401
end
call_next(env)
end
require "kemal"
require "pg"
DB = PG.connect(ENV["DATABASE_URL"])
get "/" do |env|
env.response.content_type = "application/json"
result = DB.exec("SELECT id, username FROM members LIMIT 1000")
result.to_hash.to_json
end
module TimeZone
DAYLIGHT = [
{name: 'Dateline Daylight Time', offset: -12, alt: 'International Date Line West'},
{name: 'UTC-11', offset: -11, alt: 'International Date Line West'},
{name: 'Hawaiian Daylight Time', offset: -10, alt: 'Hawaii'},
{name: 'Alaskan Daylight Time', offset: -9, alt: 'Alaska'},
{name: 'Pacific Daylight Time', offset: -8, alt: 'Pacific Time (US & Canada)'},
{name: 'US Mountain Daylight Time', offset: -7, alt: 'Mountain Time (US & Canada)'},
{name: 'Mountain Daylight Time', offset: -7, alt: 'Mountain Time (US & Canada)'},
{name: 'Central America Daylight Time', offset: -6, alt: 'Central Time (US & Canada)'},
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="#" onclick="process.mainModule.exports.printer()">Click to print</a>
</body>
</html>
# find dependencies
asterisk/contrib/scripts/install_prereq
# dialplan examples
exten => some_ext,priority,application
same => n(label),application
same => n,Goto(label) ;comments
@jwoertink
jwoertink / directive.coffee
Last active August 29, 2015 14:07
A small timer directive for AngularJS
# assumes there's already a window.timer = {}
app.directive 'callTimer', ->
opts =
restrict: 'E'
controller: ($scope, $rootScope)->
$scope.minutes = (window.timer?.state.minutes || 0)
$scope.seconds = (window.timer?.state.seconds || 0)
$scope.$on 'start-timer', -> $scope.startTimer()
require 'spec_helper'
describe HomeController do
describe '#show' do
it 'renders the taco view when params[:page] is set to taco' do
get(:show, :page => 'pricing')
response.should render_template('home/pricing')
end
end