Skip to content

Instantly share code, notes, and snippets.

View bastien's full-sized avatar

Bastien Vaucher bastien

  • Zendesk
  • Copenhagen, Denmark
View GitHub Profile
@bastien
bastien / gist:704
Created July 22, 2008 07:51
Scroll to the bottom of an element using Prototype and Scriptaculous wokrs under Firefox and Safari (not tested under ie)
/* Scroll to the bottom of an element using Prototype and Scriptaculous
wokrs under Firefox and Safari (not tested under ie)
*/
function scrollToBottom(element)
{
var offset= window.innerHeight - $(element).getHeight() -10 ;
Effect.ScrollTo(element, {offset:-offset})
}
# Extracts the hexadecimal code from a string and converts it into the corresponding unicode character
#
# code found there -> http://www.nabble.com/Euro-currency-symbol-td22795833.html ( by David Wright )
def convert(code)
return [code.gsub("U+", "").hex].pack("U")
end
puts convert("U+634F") # -> 捏
# Given a chinese character, fetch its ethymology through http://www.internationalscientific.org/
#
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'cgi'
def get_ethymology(chinese)
doc = Hpricot(open("http://www.internationalscientific.org/CharacterASP/CharacterEtymology.aspx?characterInput=#{ CGI.escape(chinese) }"))
@bastien
bastien / irbrc.rb
Created July 8, 2009 14:21
To show SQL Statements in the rails console
# To show SQL Statements in the rails console
# copy this code to ~/.irbrc
# code found there http://frozenplague.net/2008/12/showing-sql-statements-in-scriptconsole/
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end
@bastien
bastien / gist:1106844
Created July 26, 2011 14:05
Failing to creating the dialog switcher
#include "VCPlugInHeaders.h"
// Interface includes:
#include "ISession.h"
#include "IApplication.h"
#include "IDialogMgr.h"
#include "IDialog.h"
#include "IDialogCreator.h"
#include "IK2ServiceProvider.h"
@bastien
bastien / gist:1154270
Created August 18, 2011 15:10
Working S3 Policy
bucket = ENV['S3_BUCKET']
access_key = ENV['S3_KEY']
secret = ENV['S3_SECRET']
key = "temp/"
content_type = "application/pdf"
expiration = 5.hours.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
max_filesize = 500.megabytes
acl = 'public-read'
policy = Base64.encode64(
"{'expiration': '#{expiration}',
@bastien
bastien / input.txt
Created September 6, 2011 14:23
Trying to write out files in UTF-8 that TextEdit, Pages, Word and open
Danish: æåø
Chinese: 我真累
@bastien
bastien / CustomFlattenerPreset.jsx
Created December 6, 2011 11:49
Script generating custom PDF flattener export presets for InDesign
main();
function main(){
var myFlattenerPresetName = "MyCustomFlattenerPreset";
var myPDFExportPresetName = "MyPDFExport";
var tempFlattenerPreset = app.flattenerPresets.itemByName(myFlattenerPresetName);
if(tempFlattenerPreset != null){
tempFlattenerPreset.remove();
}
var flattenerlevel = FlattenerLevel.LOW;
@bastien
bastien / indesign_singlepage_replace.jsx
Created June 21, 2012 11:19
Imports a single page InDesign document into another
var doc = app.activeDocument;
var docPath = doc.fullName;
var importDoc = app.open(File('~/test_extract.indd'), false);
var pageToImport = importDoc.pages.firstItem();
importDoc.pages.add(LocationOptions.AT_END); // Documents must have at least 1 page
pageToImport.move(LocationOptions.AFTER, doc.pages.firstItem());
doc.pages.item(2).remove();
importDoc.close(SaveOptions.no);