Skip to content

Instantly share code, notes, and snippets.

View namiwang's full-sized avatar
🎯
2024

Nami W namiwang

🎯
2024
View GitHub Profile
@tcr
tcr / selection.coffee
Created June 13, 2011 01:28
Cross-Browser Selection Utilities
########################################################################
# Cross-Browser Selection Utilities
# Provides a 'selection' object with an API supporting
# all modern browsers (using window.getSelection())
# and IE5+ (using TextRanges)
########################################################################
root = this
if root.getSelection
@jwreagor
jwreagor / set.coffee
Created September 6, 2012 05:03
A simple Set class with set operations in CoffeeScript
class window.Set
constructor: (array) ->
if not array
@values = []
else
if array.constructor is Set
return new Set array.values
if array.constructor is Array
@benweint
benweint / threads-across-fork.rb
Last active May 12, 2016 08:28
threads across fork Ruby demo
#!/usr/bin/env ruby
# Pass 'fork' as the first argument to use Process.fork, otherwise Process.daemon is used.
do_fork = (ARGV[0] == 'fork')
thread = Thread.new do
loop { sleep(1) }
end
path = require 'path'
webpack = require 'webpack'
exec = require 'exec-sync'
gemDir = (name) ->
exec('bundle show ' + name)
refileDir = path.join(gemDir('refile'), 'app/assets/javascripts')
jqueryRailsDir = path.join(gemDir('jquery-rails'), 'vendor/assets/javascripts')
@rjungemann
rjungemann / dispatcher.rb
Created February 26, 2010 03:19
Simple Ruby event dispatcher
# simple event dispatcher implementation
module Evented
class Dispatcher < Array
def call *args; self.each do |e|; e.call *args end end
end
class Dispatchers < Hash
def call name, *args; self[name].call(*args) if self[name] end
end
@SlicedSilver
SlicedSilver / Polymer Application Loading Screen.md
Last active February 21, 2017 02:04
Polymer Application Loading Screen

This is a simple snippet for adding a loading screen to a Polymer application. It is useful if your Polymer application is rather large and some users may be on a very slow internet connection.

The basic idea is that a very simple (and small) loading screen page will be loaded by the browser. When the browser has fully loaded and displayed the loading page then it will start loading all the files required for the Polymer application.

For a further speed improvement: the loading.css, and polymerAppLoader.js files can be placed inline with the index.html thus reducing the amount of files to be loaded from the server.

filestoload.html is a seperate file so that the usual grunt/gulp build functions can still be applied as before. Shouldn't require re-writting your build scripts.

Any improvements/comments are encouraged.

@hisea
hisea / nginx
Created January 1, 2012 23:37
ubuntu passenger nginx init.d script
sudo cp nginx /etc/init.d/
sudo update-rc.d nginx defaults
sudo chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
@kinopyo
kinopyo / gist:2426829
Created April 20, 2012 07:23
Ruby: Get module name or class name without module
n = Notification::Answer.new
n.class.name.split('::').last || ''
# => "Answer"
n.class.name.split('::').first || ''
# => "Notification"
@jameslafa
jameslafa / admin-projects.rb
Created July 17, 2013 10:28
Paperclip with Rails4 and active admin
ActiveAdmin.register Project do
# Don't forget to add the image attribute (here thumbnails) to permitted_params
controller do
def permitted_params
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list]
end
end
form do |f|
@dchest
dchest / randomString.js
Last active December 22, 2019 08:19
Generates cryptographically secure uniform random string in browsers and Node.js [IN DEVELOPMENT]
// randomString(length)
// --------------------
//
// Generates and returns a cryptographically secure
// uniform alphanumeric random string.
//
// Examples:
//
// randomString(14) // "oXYWpc1vODNR3M"
// randomString.hex(8) // "663c722b65943b9b"