Skip to content

Instantly share code, notes, and snippets.

View peterssonjesper's full-sized avatar

Jesper Petersson peterssonjesper

View GitHub Profile
#!/usr/bin/python
import sys, re, os
SCAN_EXTENSIONS = ["js", "html", "php", "py", "rb"]
def error_in_line(line):
return True if re.search(",}", line) else False# Check inside a line
def search_file(filename):
try:
@peterssonjesper
peterssonjesper / gist:3286510
Created August 7, 2012 15:44
Inheritance example Javascript
// Parent class with two properties, one integer and one object
var ParentClass = function() {
this.counter = 0;
this.obj = { counter : 0 };
this.inca = function() {
this.counter++;
this.obj.counter++;
}
};
#include <iostream>
void tree(int d, int n);
long long int found = 0;
int target = 1000000;
void tree(int d, int n) {
if(d > target)
return;
found += 1;
from math import sqrt
d = pow(10, 6)
factors = [-1, -1]
primes = []
def phi(i):
res = 1
index = 0
while index < len(factors[i]):
@peterssonjesper
peterssonjesper / 28.c
Created September 17, 2012 20:19
Project Euler - Problem 28
#include <stdio.h>
#define ROWS 1001
int main() {
int levels;
int sum = 0;
int corner = 1;
int row_length = 2;
for(levels = 0; levels < ROWS/2; ++levels) {
sum += (2*corner + row_length*3)*2;
@peterssonjesper
peterssonjesper / grunt.js
Created October 11, 2012 19:44
Sample grunt configuration
module.exports = function(grunt) {
grunt.initConfig({
// Javascript minification
min : {
code : {
'src' : [
'public/js/file1.js',
'public/js/file2.js',
'public/js/file3.js'
],
@peterssonjesper
peterssonjesper / create-boxshadow-css.js
Created October 17, 2012 23:46
Creates a boxshadow based on an image
// Create an empty canvas
var canvas = document.createElement('canvas');
// Create an image
var img = new Image();
img.src = "http://path/to/image.png";
// Wait for image to be downloaded
img.onload = function() {
// Draw the image on the canvas
describe("My module", function() {
it("answers to myMethod() correctly", function() {
var instance = new MyModule();
expect(instance.myMethod()).toEqual("Hello world");
});
});
watch: {
js: {
files: [
'public/javascripts/src/**/*.js',
'public/javascripts/spec/**/*.js'
],
tasks: ['jasmine:all']
}
}
istanbul: {
src: '<%= jasmine.all.src %>',
options: {
vendor: '<%= jasmine.all.options.vendor %>',
specs: '<%= jasmine.all.options.specs %>',
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
coverage: 'coverage/json/coverage.json',
report: [
{type: 'html', options: {dir: 'coverage/html'}},