Skip to content

Instantly share code, notes, and snippets.

View pketh's full-sized avatar
🐢
https://kinopio.club

Pirijan pketh

🐢
https://kinopio.club
View GitHub Profile
@pketh
pketh / background-animations.css
Created January 20, 2015 04:44
animating background colors with css
/* ripped off from ea1.co */
/* (just add vendor prefixes) */
body {
animation: background-animation-cool 5s linear infinite alternate;
}
section:nth-child(2n+1) {
animation: background-animation-warm 5s linear infinite alternate;
}
@pketh
pketh / each type loops.coffee
Created January 31, 2015 17:46
You don't need each, collect or select in Coffeescript
# from http://makandracards.com/makandra/18605-you-don-t-need-each-collect-or-select-in-coffeescript
## each
for item in items
...
## collect / map
ages = (person.age for person in people)
## select / grep
@pketh
pketh / emailvalidation.js
Created March 9, 2015 15:38
basic email validation
function isValidEmail(input) {
var trimmedInput = $.trim(input),
hasSpaces = trimmedInput.indexOf(' ') !== -1, // true if no spaces
matchesBasicEmailPattern = trimmedInput.match(/@.*[.]/);
return matchesBasicEmailPattern && !hasSpaces;
}
@pketh
pketh / rem-sizing
Created April 1, 2015 18:04
easy CSS font sizing
html
font-size: 62.5%
body
font-size: 1.6rem // = 16px
@pketh
pketh / emails.coffee
Last active August 29, 2015 14:18
validates emails with hooks for doing other things
validateEmail = (email, input) ->
emailPattern = /^[A-Za-z0-9](([_\.\-+]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/i
if emailPattern.test(email)
addSuccessCookie()
return true
else
input.addClass('fail')
return false
addSuccessCookie = () ->
@pketh
pketh / server.rb
Last active August 29, 2015 14:19 — forked from clody69/server.rb
require 'sinatra'
require 'haml'
$users = {'john' => {:roles => [:user] }, 'mike' => {:roles => [:user, :admin] } }
$tokens = {'123' => {:username => 'john', :expires_at => Time.now+60}}
helpers do
def authenticate_user!
@auth_token = auth_token
if $tokens.has_key?(@auth_token) && !$tokens[@auth_token][:expires_at].nil? && $tokens[@auth_token][:expires_at] > Time.now
@pketh
pketh / git-recent.sh
Created September 28, 2015 19:42
List my recent git branches
# add this line to your .bash-profile (.bashrc should also work)
# call this in a repo folder with `git-recent`
alias git-recent="git for-each-ref --count=5 --sort=-committerdate refs/heads/ --format='🌺 %(refname:short)'"
@pketh
pketh / bouncy.coffee
Created December 1, 2015 00:32
bouncy links (adapted from shauninman.com/pendium)
# bouncy links
$('a').each ->
$(this).mousemove (e) ->
if this.isAlreadyAnimating
console.log 'still animating: ', this.isAlreadyAnimating
else
baseExpX = 4 # 2 ^ 4 == 16
baseExpY = 2 # 2 ^ 4 == 16
@pketh
pketh / color-cycling.coffee
Last active July 9, 2018 00:04
smooth color cycling backgrounds
target = $('body')
# get random RGB values so we can change background and link colors
r = Math.floor Math.random() * 241
g = Math.floor Math.random() * 241
b = Math.floor Math.random() * 241
# variables to hold the lighter shade RGB values
# rp1; gp1; bp1; rp2; gp2; bp2; rp3; gp3; bp3
@pketh
pketh / conditional evaluation.coffee
Created December 3, 2015 19:01
tests multiple items to see if that item should be excluded
dothis = ->
console.log 'do this'
dothistoo = ->
console.log 'do this too'
dox = ->
console.log 'do x'
text = (x) ->