Skip to content

Instantly share code, notes, and snippets.

{
"client": {
"grants": [
{
"scopes": [{}]
}
],
"sessions": [
{
"authcodes": [
class Event < ActiveRecord::Base
self.table_name = "events_event"
has_and_belongs_to_many :artists, { :join_table => "events_event_artists" }
attr_accessor :localized_date, :month
def localized_date
I18n.localize(read_attribute(:date), :format => "%d %b")
end
def month
@Xlator
Xlator / event.rb
Created October 14, 2012 01:57
Rails model with virtual property for json request
class Event < ActiveRecord::Base
self.table_name = "events_event"
has_and_belongs_to_many :artists, { :join_table => "events_event_artists" }
attr_accessor :localized_date
def localized_date=(date)
write_attribute(:date, I18n.localize(date, :format => "%b"))
end
def localized_date
@Xlator
Xlator / cleverbot.log
Created April 14, 2012 14:00
cleverbot log
09:26:54 User: I'm being so sincere right now.
09:26:59 Cleverbot: Even though you broke my heart and killed me.
09:27:29 User: And tore me to pieces.
09:27:33 Cleverbot: And threw every piece into a fire.
09:27:56 User: As they burned it hurt because I was so happy for you!
09:28:01 Cleverbot: Now these points of data make a beautiful line.
09:28:21 User: And we're out of beta, we're releasing on time!
09:28:25 Cleverbot: So I'm glad I got burned, think of all the things we learned.
09:28:58 User: For the people that are still alive.
09:29:05 Cleverbot: Go ahead and leave me.
@Xlator
Xlator / Kittens.cs
Created April 11, 2012 20:15
Kittens.cs - A simple example class to illustrate constructors, methods and access modifiers
class Kitten
{
string Colour = String.Empty; // Colour of kitten.
/* The "default" value of a string is null, NOT an empty string.
If this is a value that won't always be set, we should declare it as an empty string. */
string Name = String.Empty;
int Age; // Age in months.
bool Fluffy; // Whether or not kitten is fluffy.
<?php
if(isset($_GET['url'])) {
if(!isset($_GET['type'])) {
die();
}
$page = file_get_contents(urldecode($_GET['url']));
if($_GET['type'] == "lesson") {
preg_match('#href="(.*?)">Download video#',$page,$link);
preg_match("#<div class=\"entry-content\">(.*?)<\/div>#usm",$page,$content);
/* print $link[0]; */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Uppgifter3
{
class Program
{
@Xlator
Xlator / 1.php
Created February 16, 2012 07:41
<?php if(isset($_GET["fuckit"])) { // Remove the data file and redirect
unlink("data");
header("Location: ./1.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<?php
function ocr($str) {
$counts = array_filter(count_chars($str));
// Length of string divided by length of character count array
// gives us the average occurences of each character
$avg_occurences = strlen($str) / count($counts);
foreach($counts as $char => $count) {
SELECT (IFNULL(l.links,0)+IFNULL(c.comments,0)) AS points FROM
(SELECT users.id AS id, sum(v.vote) as links FROM users
LEFT JOIN links ON links.user=users.id
LEFT JOIN votes as v ON v.subjectid=links.id AND v.type='link' GROUP BY id) as l
JOIN (SELECT users.id AS id, sum(v.vote) as comments FROM users
LEFT JOIN comments ON comments.userid=users.id
LEFT JOIN votes as v ON v.subjectid=comments.id AND v.type='comment' GROUP BY id) as c
ON l.id=c.id WHERE c.id=$userid GROUP BY c.id";