Skip to content

Instantly share code, notes, and snippets.

@agibralter
agibralter / random_attribute.rb
Created September 25, 2012 16:31
ActiveRecord random unique hash
module RandomAttribute
def generate_unique_random_base64(attribute, n)
until random_is_unique?(attribute)
self.send(:"#{attribute}=", random_base64(n))
end
end
def generate_unique_random_hex(attribute, n)
until random_is_unique?(attribute)
@jpmckinney
jpmckinney / .block
Last active June 29, 2020 16:34
WeWork Place Ville-Marie Mac OS X Printing Instructions
license: cc-by-4.0
@kiding
kiding / hangulJosa.js
Created October 9, 2014 16:42
한글 조사 자동 선택 스크립트
/**
* 한글조사 - 은/는 이/가 을/를 과/와 이여/여
* @author Dongsung Don Kim <kiding@me.com>
* @license MIT
*/
// TODO: 으로/로
var hangulJosa = (function() {
var reT = /[0136-80136-8L-NRL-NRㄱ-ㅎ\uFFA1-\uFFBE\u3165-\u3186\u1100-\u115E\u11A8-\u11FF]/,
// 영일삼육칠팔 반각 전각, 대문자 알파벳 엘엠엔 반각 전각, 자음, 반각 자금, 옛자음, 조합 초성, 조합 종성
reF = /[24592459A-KO-QS-ZA-KO-QS-Zㅏ-ㅣ\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\u3187-\u318E\u1161-\u11A7]/;
@mefellows
mefellows / ec2-user-data.ps1
Last active May 28, 2021 11:44
Packer Community Plugins - Example Windows 2012 Setup
<powershell>
write-output "Running User Data Script"
write-host "(host) Running User Data Script"
cmd.exe /c net user /add vagrant FooBar@123
cmd.exe /c net localgroup administrators vagrant /add
Set-ExecutionPolicy -ExecutionPolicy bypass -Force
# RDP
@masonforest
masonforest / gist:4048732
Created November 9, 2012 22:28
Installing a Gem on Heroku from a Private GitHub Repo

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

  1. Get an OAuth Token from GitHub

First you will need to get an OAuth Token from GitHub using your own username and "note"

@allieus
allieus / gist:1180051
Last active June 25, 2022 18:10
wgs84/tm127/tm128/grs80/cyworld 간 좌표변환
'''
aero님께서 구현하신 구글/네이버/싸이월드/콩나물 좌표변환은 펄/자바스크립트로 되어있습니다.
펄/자바스크립트에 익숙지 않은지라, 수식을 파이썬으로 번역해보았습니다.
'''
from pyproj import Proj
from pyproj import transform
WGS84 = { 'proj':'latlong', 'datum':'WGS84', 'ellps':'WGS84', }
@avdi
avdi / gist:7990684
Created December 16, 2013 17:20
Streaming a URL to a file in Elixir
def download_video(Episode[filename: filename] = episode) do
Stream.resource(fn -> begin_download(episode) end,
&continue_download/1,
&finish_download/1)
|> File.stream_to!(filename)
|> Stream.run
end
def begin_download(Episode[video_url: video_url,
account: Account[login: login,
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@maxivak
maxivak / readme.md
Last active March 25, 2023 01:56
sitemap.xml for Rails 4 application

Generate sitemap.xml in Rails app

This post shows how to make sitemap.xml for your web site. The sitemap will be accessible by URL http://mysite.com/sitemap.xml

Routes

Myrails::Application.routes.draw do
@lpar
lpar / timeout.rb
Created June 17, 2011 20:41
Run a shell command in a separate thread, terminate it after a time limit, return its output
# Runs a specified shell command in a separate thread.
# If it exceeds the given timeout in seconds, kills it.
# Returns any output produced by the command (stdout or stderr) as a String.
# Uses Kernel.select to wait up to the tick length (in seconds) between
# checks on the command's status
#
# If you've got a cleaner way of doing this, I'd be interested to see it.
# If you think you can do it with Ruby's Timeout module, think again.
def run_with_timeout(command, timeout, tick)
output = ''