Skip to content

Instantly share code, notes, and snippets.

View ymek's full-sized avatar

Myke Stubbs ymek

  • cyberspace
View GitHub Profile
#!/bin/bash
filename='/tmp/newdata.json'
while read line; do
if [ -z "$(echo $line | grep -vP "^$" | grep -vP "^//")" ]; then
echo > /dev/null
else
query="db.foo_collection.insert($line)"
echo -e "$("mongo localhost/my_db_name --eval \"'$query'\"")\n\n"
# In this scenario, we initialize the variable,
# which is parsed *after* we access it, because
# the interpreter is always left-to-right.
[] << walrus if (walrus = :bubbles)
# Note: the value *does* change before the append
# happens.
walrus = nil
[] << walrus if (walrus = :bubbles)
@ymek
ymek / gist:3922731
Created October 20, 2012 09:06
Create self-signed certificate for nginx
# cd /etc/nginx/
# openssl genrsa -des3 -out server.key 1024
# openssl req -new -key server.key -out server.csr
# cp server.key server.key.org
# openssl rsa -in server.key.org -out server.key
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
# Example /etc/nginx/sites-available/my_project.conf
server {
listen 443;
def get_names_dates_and_urls
data = {}
self.full_match_file.tap { |info| data[info[:date]] = info if should_process_file?(info[:date]) }
get_incremental_names_dates_and_urls.each { |info| data[info[:date]] = info if should_process_file?(info[:date]) }
data
end
# match a TLD from a referrer (rails 3)
request.referrer[/^(?:(?:http|https)):\/\/(?:[a-z0-9]+(?:[\-\.]{1}))?([a-z0-9]+*\.[a-z]{2,5})/, 1]
> db.things.insert({'content' : {'foo': []}})
> db.things.find()
{ "_id" : ObjectId("50512dd15e5110032d1fa00d"), "content" : { "foo" : [ ] } }
> db.things.update({ _id : ObjectId("50512dd15e5110032d1fa00d") }, { $set : { 'content.foo.0' : {bar: 5} } })
> db.things.find()
{ "_id" : ObjectId("50512dd15e5110032d1fa00d"), "content" : { "foo" : [ { "bar" : 5 } ] } }
> db.things.update({ _id : ObjectId("50512dd15e5110032d1fa00d") }, { $set : { 'content.foo.1' : {bar: 5} } })
> db.things.find()
def spawn_child(command, wait_for_child = true)
log_status "Spawning #{command}"
child_pid = Process.spawn(command)
if wait_for_child
if (status = Process.wait2(child_pid).last.exitstatus) != 0
log_status("itunes_match_importer exited with code: #{status}", :error)
#exit(1)
else
log_status("#{command} completed")
end
fname, version, ext = key.match(/([a-z0-9]+)(_v[0-9]+)?(\..{3,4})/i).captures
version = (version ? "_v#{version[/[0-9]+/].to_i + 1}" : '_v2')
new_key = fname + version + ext
def thumbify
path = File.join(Rails.root, 'tmp', 'broken_art')
original_image = 'c11c42280223d6a199c0ffe069a2949ef07ff42a.jpg'
ImageScience.with_image(File.join(path, original_image)) do |image|
styles = {
thumb: { width: 75, height: 75, thumbnail: true, async: true },
small: { width: 150, height: 150, thumbnail: true, async: true },
medium: { width: 320, height: 320, thumbnail: true, async: true },
large: { width: 640, height: 640, thumbnail: true }
[merge]
ff = only
[rerere]
enabled = 1
[alias]
st = status
di = diff
co = checkout