Skip to content

Instantly share code, notes, and snippets.

View Shadowfiend's full-sized avatar
💇
Studioin'.

Antonio Salazar Cardozo Shadowfiend

💇
Studioin'.
View GitHub Profile
@Shadowfiend
Shadowfiend / Bundles.scala
Created May 25, 2012 21:40
Lift snippet for bundle support in conjunction with Shadowfiend/sbt-resource-management.
package com.openstudy { package snippet {
import scala.xml._
import java.io.InputStreamReader
import net.liftweb.common._
import net.liftweb.http._
import LiftRules._
import net.liftweb.util._
import Helpers._
@Shadowfiend
Shadowfiend / package.scala
Created May 8, 2012 21:39
Functions for extracting field names for Lift server-side functions as Strings.
package com {
package object openstudy {
def nameForStringField(fn:(String)=>Any) : String = {
S.fmapFunc(S.SFuncHolder(string => fn(string)))((name:String) => name)
}
def nameForFileUploadField(fn:(FileParamHolder)=>Any) : String = {
S.fmapFunc(S.BinFuncHolder(fph => if (fph.length > 0) fn(fph)))((name:String) => name)
}
def nameForSubmitButton(fn:()=>JsCmd) : String = {
S.fmapFunc(S.NFuncHolder(fn))((name:String) => name)
@Shadowfiend
Shadowfiend / gist:2580081
Created May 2, 2012 20:19
A WeakReference-ish class that allows for restoring its argument with a function.
class RestoringWeakReference[T <: AnyRef](private var reference:WeakReference[T], restorer:()=>T) {
def value : T = {
val existing = reference.get
if (! existing.isDefined) {
restoreReference
value
} else {
existing.get
}
}
// Helpers for distances in words.
class TimeDeltaHelpers(timeDelta:Long) {
// Turns the time delta (in milliseconds) into a word distance, e.g. `5
// days ago' or `3 hours ago'.
def distanceInWords : String = {
fuzzyTimeFromDelta(timeDelta)
}
private val second = 1
private val minute = 60 * second
@Shadowfiend
Shadowfiend / ReloadOnSessionLoss.scala
Created April 6, 2012 03:04
Drop-in reloading of a client on session loss based on calling a local window.serverReload function.
package bootstrap.liftweb {
import net.liftweb.common._
import net.liftweb.http._
import js._
import LiftRules._
import net.liftweb.util.Helpers._
/**
* Provides automatic reloading of the client on session loss.
*
@Shadowfiend
Shadowfiend / gist:1089719
Created July 18, 2011 14:45
JS to set up popup with arrow.
function loadTooltip(tooltipHtml) {
var $tooltip = $(tooltipHtml);
$tooltip.append('<div class="arrow" />');
$('body').append($tooltip.hide());
$tooltip.fadeIn();
}
@Shadowfiend
Shadowfiend / gist:1089717
Created July 18, 2011 14:44
HTML for popups with arrows
<div class="popup left-arrow">
<h5>Stumped?</h5>
<p>Post your question here and other people on OpenStudy will help you find
the answer!</p>
<a class="close">close</a>
<div>
<input id="hide-tips" type="checkbox" />
<label for="hide-tips">Don't show tips</label>
@Shadowfiend
Shadowfiend / gist:1040867
Created June 22, 2011 19:11 — forked from nomothetis/gist:1040861
Fish script for committing to SVN via git-svn
# This script requires fish-nuggets, available at:
# http://github.com/nirvdrum/fish-nuggets
function svnc --description "Commit from git master to SVN."
if not is-git
echo "svnc can only be run from a git repository."
return
end
set -l branch (env git symbolic-ref -q HEAD)
@Shadowfiend
Shadowfiend / nativeTemplateEngine.js
Created June 20, 2011 05:23 — forked from mjtko/nativeTemplateEngine.js
knockout "native" template engine
ko.nativeTemplateEngine = function () {
function nodeListToArray(nodeList) {
var array = [];
for (var i = 0; i < nodeList.length; ++i)
array[i] = nodeList[i];
return array;
}
@Shadowfiend
Shadowfiend / gist:965176
Created May 10, 2011 19:17
ReloadOnSessionLoss.setup can be run in Boot.scala
package bootstrap.liftweb {
import net.liftweb.common._
import net.liftweb.http._
import js._
import LiftRules._
import net.liftweb.util.Helpers._
/**
* Provides automatic reloading of the client on session loss.
*