Skip to content

Instantly share code, notes, and snippets.

🤘
Elixir, React, Phoenix, Rust.

Anders Ytterström madr

🤘
Elixir, React, Phoenix, Rust.
View GitHub Profile
@madr
madr / javascript.js
Last active Jan 21, 2016
String replacement using regular expressions
View javascript.js
var results = 'hi bob123';
results = results.replace(/bob\d+/, 'cooper');
@madr
madr / example-infinitescroll.js
Last active Dec 31, 2015
Primitive scroll guard utility
View example-infinitescroll.js
/*jslint browser: true, indent: 4 */
/*
Example use of ScrollGuard: a simple, unobtrusive lazy loader.
Each time the user scrolled to the bottom of the page:
1. Look if there is content to load (lookForNextPage)
2. If new content, get content using Ajax (getNextPage)
3. Append the new content and do some polish (appencContent)
View gist:7802137
<a href="javascript:(function(){(function(){var%20doc,reload,keepAlive,saveButton,title;title=window.bajsa;doc=document.querySelectorAll("frame")[1].contentWindow;reload=function(){if(window.bajsa!==undefined){console.log("who%20is%20gabriel");doc.location.reload();keepAlive=setTimeout(reload,5*1000);}};if(title!==undefined){clearTimeout(keepAlive);delete%20window.bajsa;console.log("CANCELLED")}else{window.bajsa="who%20is%20gabriel";reload();}}());})();">Keep Agresso Alive</a>
@madr
madr / Gruntfile.js
Last active Dec 27, 2015
Frontend QA and deploy using Grunt, including: HTML validation (validator.nu), KSS styleguide generation, JSLint, CSSLint, Jasmine and deployment (concatination, minification and compression of CSS and JavaScript). Use setup.sh to create folder structures and get all dependencies installed (the script will download the oher files).
View Gruntfile.js
/*
The Following folder structure is required:
./
./dist
app.js
app.min.js
app.min.zipped.js
design.css
design.min.css
View characters.js
var ಠ_ಠ = eval,
ლ_ಠ益ಠ_ლ = 42,
λ = function() {},
oneQuarter = "¼",
oneHalf = "½",
threeQuarters = "¾";
// ☺
// ¯\_(ツ)_/¯
// ಠ~ಠ
@madr
madr / validate_html.rb
Created Oct 15, 2013
Validate HTML using ruby
View validate_html.rb
require "rubygems"
require 'living-validator'
require 'uri'
url = ARGV.first
files = ARGV.slice(1, 9999)
stop_at = files.length
i = 1
def colorize(text, color_code)
@madr
madr / ftp_upload.rb
Created Oct 15, 2013
Upload static files to a FTP server based on a git diff
View ftp_upload.rb
require "rubygems"
require 'net/ftp'
require 'stringio'
ftp = ""
username = ""
passwd = ""
root_dir = "../../../../"
current_rev_file = root_dir + "__CURRENT_VERSION__"
@madr
madr / gist:5443213
Created Apr 23, 2013
Bash: quickly adding a vhost to MAMP basic
View gist:5443213
#!/bin/bash
#
# usage: ./adp-new-vhost <name>
#
mampdir=/Applications/MAMP
confdir=$mampdir/conf/apache/extra/vhosts
codedir=~/Code
mampport=80
cat <<end > $confdir/$1.conf
@madr
madr / cssembed
Created Apr 4, 2013
Embed Images as data-URIs in CSS files
View cssembed
#!/usr/bin/env python
import base64, re, argparse
parser = argparse.ArgumentParser(description='CSS-Embed PNG images as data-URIs')
parser.add_argument('files', metavar='file', nargs="+", type=str,
help='path to a css file')
img = re.compile("url\('?\"?(.*\.png)'?\"?\)")
repl = "url(data:image/png;base64,%s)"
You can’t perform that action at this time.