Skip to content

Instantly share code, notes, and snippets.

View joshbeckman's full-sized avatar
👍

Josh Beckman joshbeckman

👍
View GitHub Profile
@joshbeckman
joshbeckman / gist:5949332
Last active December 19, 2015 11:39
ColorType in-browser text editor, rainbow-effect
data:text/html,
<html>
<head>
<title>ColorType</title>
<link href='http://fonts.googleapis.com/css?family=Merriweather' rel='stylesheet' type='text/css'>
<style type="text/css">
html { font-family: "Merriweather" } * { -webkit-transition: all linear 1s; }
</style>
<script>
window.onload=function(){
@joshbeckman
joshbeckman / gist:6625050
Created September 19, 2013 15:17
Dump data from a heroku pg databse into a local csv.
# Run in bash:
heroku pg:psql
# Run in the psql CLI:
\copy (SELECT id, name, longitude, latitude FROM cities) TO cities.csv CSV DELIMITER ','
# Run in the psql CLI:
\q
# Voila! csv is in your pwd
@joshbeckman
joshbeckman / gist:6625059
Created September 19, 2013 15:17
Client-side full-text filter in CSS
<input type="text" placeholder="filter" id="filter">
<ul class="contacts">
<li class="filterable" data-index="all my lower case search terms">
All my lower case search terms
</li>
<li class="filterable" data-index="lowerlowercasecase">
Lower lower case case
</li>
<!-- add as much data as you want, add the selector class and add the terms in data-index -->
</ul>
@joshbeckman
joshbeckman / gist:6625074
Created September 19, 2013 15:18
Convert seconds integer to mm:ss format
t = Time
min = (t/60).to_s
sec = (t-(60*(t/60))).to_s
sec.length == 1 ? (sec = '0'+sec) : (sec = sec)
min+':'+sec
@joshbeckman
joshbeckman / gist:6625088
Created September 19, 2013 15:19
Generate random users from the randomuser API. Tested locally.
int = 0
x = 5
x.times do |t|
json = HTTParty.get('http://randomuser.me/g/?seed=your-app-name'+int.to_s)
unless User.find_by_email(json['user']['email'])
User.transaction do
new_u = User.create(name: json['user']['name']['first'].capitalize+' '+json['user']['name']['last'].capitalize, email: json['user']['email'], password: '@ggrego22')
puts 'Welcome '+json['user']['name']['first']+' '+json['user']['name']['last']
new_u.remote_image_url = json['user']['picture']
new_u.save!
@joshbeckman
joshbeckman / gist:6706624
Created September 25, 2013 21:55
Truncate strings of text and append a link to show the full text
var len = 100;
var p = document.getElementsByClassName('truncate');
if (p) {
for(i=0;i<p.length;i++){
var trunc = p[i].innerHTML;
if (trunc.length > len) {
/* Truncate the content of the P, then go back to the end of the
previous word to ensure that we don't truncate in the middle of
a word */
@joshbeckman
joshbeckman / gist:6717179
Created September 26, 2013 17:05
Simple function to get all url query parameters for current page
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
@joshbeckman
joshbeckman / animatedScrollTo.js
Created September 30, 2013 14:51
ScrollTo animation using pure javascript and no jquery
document.getElementsByTagName('button')[0].onclick = function () {
scrollTo(document.body, 0, 1250);
}
function scrollTo(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20;
@joshbeckman
joshbeckman / gist:6784495
Created October 1, 2013 20:21
Simple replacement for the sequence of creating a DOM element and assign properties
var create = function(name, props){
var el = document.createElement(name);
for (var p in props) el[p] = props[p];
return el;
};
@joshbeckman
joshbeckman / judo.js
Last active December 24, 2015 16:29
Judo.js is tiny front-end javascript library of utilitarian mini-functions for custom development. Like physical judo leveraging the opponent against him/herself, this library leverages the browser into manipulating itself.
window.judo = {
scrollTo: function(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20,
easeInOutQuad = function (t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t + b;
t--;