Skip to content

Instantly share code, notes, and snippets.

module SimpleHashtag
class Hashtag < ActiveRecord::Base
acts_as_tenant :tenant
def self.find_by_name(name, tenant)
Hashtag.where("lower(name) =? AND tenant_id=?", name.downcase, tenant.id).first
end
def self.find_or_create_by_name(name, tenant, &block)
find_by_name(name, tenant) || create(name: name, &block)
#!/usr/bin/env ruby
#coding: utf-8
require 'pp'
word = {}
tweets = []
final = {}
File.open("mapreduce.csv", "r:windows-1251:utf-8").each_line do |line|
line = line.split(",")
word[line[0]] = line[2]
@schatteleyn
schatteleyn / People.scala
Created October 10, 2013 18:45
find sur plusieurs paramètres
Salut Mathieu. j'ai trouvé ton code dans dans les exemples pour un find by username.
Si je veux l'adapter pour créer une méthode de login, est-ce que quelque chose de genre marcherait ?
Je suis pas sûr de bien comprendre la l.9
def login(name: String, password: String): Future[Option[People]] = {
val query = new Query().setIncludeDocs(true).setLimit(1)
.setRangeStart(ComplexKey.of(name), ComplexKey.of(password))
.setRangeEnd(ComplexKey.of(s"$name\uefff"), ComplexKey.of(s"password\uefff"))
bucket.find[People]("people", "by_name", "by_password")(query).map(_.headOption)
}
val headers_13 = Map(
"Accept" -> """*/*""",
"Origin" -> """http://site.com""",
"token" -> """token"""
)
val scn = scenario("Scenario Name")
.exec(http("request_1")
.post("http://site.com/login")
.headers(headers_1)
// ./jobs//jobs/TweetsCrawl.js
var CronJob = require('cron').CronJob;
module.exports = function(client, T, io){
var personalSpace = {};
personalSpace.tweetCount = null;
personalSpace.twitterStream = null;
@schatteleyn
schatteleyn / Firefly 1x15 ’Dead Or Alive’
Created February 8, 2013 23:24
Firefly 1x15 ’Dead Or Alive’ - Complete Transcript and donate car You don't what could happen, so here's a copy. Original here http://www.whedon.info/article.php3?id_article=8136
Firefly
"Dead or Alive"
Episode # : 1AGE06
Story # :
Written by : Cheryl Cain
Directed by : Marita Grabiak
@schatteleyn
schatteleyn / osm_test.html
Last active December 6, 2020 12:58
Little tests with OpenStreetMap and Geolocation API
<!DOCTYPE HTML>
<html>
<head>
<title>OpenLayers Test</title>
<style type="text/css">
html, body, #basicMap {
width: 100%;
height: 100%;
margin: 0;
}
@schatteleyn
schatteleyn / synch.rb
Last active December 10, 2015 19:18
Script to find and copy the movies from a computer to an external hard drive
computer = #path to movies directory
hd = #path to movies directory
def get_movies(path_comp, path_hd)
# Return ana rray with only the new movies. I exclude the directory Series in the search
return `ls #{path_comp} | grep -v Series`.split(/\n/) - `ls #{path_hd} | grep -v Series`.split(/\n/)
end
new_movies_list = get_movies(computer, hd)
@schatteleyn
schatteleyn / lineup.rb
Created December 6, 2012 13:19
Do an easy line-up
require 'trollop'
opts = Trollop.options do
banner <<-EOS
This programs help you to do a running order. Use it like this:
ruby lineup.rb -b Band "Best Band Ever" -t 30 75 -e 21 25 -s 20
Band
Set: 21:25 - 21:55
@schatteleyn
schatteleyn / gist:3930583
Created October 22, 2012 09:23
Stack Trace Error
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:364: warning: already initialized constant Revision
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:365: warning: already initialized constant HTTPVersion
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:369: warning: already initialized constant HAVE_ZLIB
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:677: warning: already initialized constant SSL_ATTRIBUTES
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1416: warning: already initialized constant HTTPSession
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2109: warning: already initialized constant METHOD
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2110: warning: already initialized constant REQUEST_HAS_BODY
/Users/username/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2111: warning: already initialized constant RESPONSE_HAS_BODY
/Users/username/.rvm/rub