Skip to content

Instantly share code, notes, and snippets.

View kurtsson's full-sized avatar

Martin Kurtsson kurtsson

View GitHub Profile
@kurtsson
kurtsson / hero.component.html
Created November 11, 2018 21:04
testar-validering-av-formular
<div class="container">
<h1>Hero Form</h1>
<form class="needs-validation was-validated">
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationCustomUsername">Username</label>
<div class="input-group">
<input [formControl]="usernameinput" type="text" class="form-control {{(usernameinput.invalid && usernameinput.dirty) ? 'is-invalid' : ''}}" id="validationCustomUsername" placeholder="Username">
<div class="invalid-feedback">
Please choose a username.
@kurtsson
kurtsson / battery.scss
Last active August 29, 2015 14:08
A battery icon made purly in CSS, heavily influated by the battery from @captainbrosset
.battery {
$bg: $bright-color;
$border: $dark-color;
$level-good: $green;
$level-bad: $red;
font-size: 2px;
display: inline-block;
width: 4.5em;
height: 11em;
border: 0.8em solid $bg;
@kurtsson
kurtsson / my_directive.coffee
Last active August 29, 2015 14:08
Custom Angular directive in CoffeeScript, the proper way
class MyDirective
constructor: (myService) ->
@controller = MyController
@controllerAs = myCtrl
restrict: 'E'
replace: true
scope:
attributeStuff: '='
link: (scope, element, attr) ->
// Link stuff
@kurtsson
kurtsson / FileList.coffee
Created October 24, 2014 22:21
FileList, list all files recursive in a directory that matches the expression
fs = require('fs')
class FileList
constructor: (dir,exp = '') ->
@fileList = []
@pattern = new RegExp(exp)
@getFiles(dir)
getFiles: (dir) ->
files = fs.readdirSync(dir)
for file in files
name = "#{dir}/#{file}"
@kurtsson
kurtsson / monkey_patch_firefox_profile.rb
Created September 30, 2014 08:40
To use a custom firefox profile for Selenium-webdriver in ruby
module Selenium
module WebDriver
module Firefox
class Profile
def layout_on_disk
firefox_profile = File.expand_path(File.join(File.dirname(__FILE__),'firefox_profile'))
profile_dir = create_tmp_copy(firefox_profile)
FileReaper << profile_dir
install_extensions(profile_dir)
@kurtsson
kurtsson / RestClient.coffee
Created September 25, 2014 12:46
Cors request with preflight using jquery and angular that works in ie, ff and webkit
class RestClient
constructor: (@endpoint,@$scope) ->
populate: (callback) ->
@populated = false
@errored = false
@data = {}
jQuery.ajax(
url: @endpoint
xhrFields:
@kurtsson
kurtsson / Rakefile
Created September 23, 2014 10:48
Install gem dependencies using rake and bundler
desc 'Install ruby dependencies'
task :install_gems do
begin
require 'bundler'
puts '## Using existing bundler installation'
rescue LoadError
puts '## Installing bundler'
system 'gem install bundler'
end
puts '## Installing gems'
@kurtsson
kurtsson / env.rb
Last active August 29, 2015 14:06
Serve a static build folder using Rack when running Capybara
require 'rack_directory_index.rb'
$documentRoot = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'build'))
Capybara.app = Rack::Builder.new do |builder|
puts "Creating static rack server serving #{$documentRoot}"
use Rack::DirectoryIndex
run Rack::Directory.new($documentRoot)
end
@kurtsson
kurtsson / formatXML.js
Last active August 10, 2023 13:22 — forked from sente/formatXML.js
formatXML.js but without jQuery dependency
function formatXml(xml) {
var formatted = '';
var reg = /(>)(<)(\/*)/g;
xml = xml.toString().replace(reg, '$1\r\n$2$3');
var pad = 0;
var nodes = xml.split('\r\n');
for(var n in nodes) {
var node = nodes[n];
var indent = 0;
if (node.match(/.+<\/\w[^>]*>$/)) {
@kurtsson
kurtsson / webfont.erb
Last active January 1, 2016 18:09
Ruby method that creates and imports a web font. Preferably used in an .css.scss.erb file to download the css for a Google Font statically. This saves an http request during page load.
<%
require 'net/http'
def require_web_font(o={})
o = {:family=>"Open Sans",:weights=>["500","500italic"],:url=>"http://fonts.googleapis.com/css"}.merge(o)
url = URI.parse(URI::encode("#{o[:url]}?family=#{o[:family]}:#{o[:weights] * ','}"))
Net::HTTP.start(url.host,url.port){|http| http.request(Net::HTTP::Get.new(url.to_s))}.body
end
%>
<%= require_web_font({ :family => "Droid Sans",