Skip to content

Instantly share code, notes, and snippets.

View joladev's full-sized avatar

Johanna Larsson joladev

View GitHub Profile
@joladev
joladev / someeuler.js
Created October 11, 2013 09:37
Some Euler problem
function solution(number){
var range = function (max) {
var nums = [];
for (var i = 0; i < max; i++) {
nums.push(i);
}
return nums;
};
return range(number)
/*
Description:
Write a function 'notQuine' which returns a string containing every ASCII character that is NOT part of the source code of the function.
The outer 'function () { }' wrapper is included.
A function containing all of the characters is not a valid solution.
You may not modify Function.prototype.toString, notQuine.toString, String.indexOf, or String.fromCharCode.
@joladev
joladev / state.js
Last active April 18, 2016 13:28
Simple AngularJS State Service for sharing state between controllers.
angular.module('services', [])
.factory('State', function ($rootScope) {
'use strict';
var state;
var broadcast = function (state) {
$rootScope.$broadcast('State.Update', state);
};
var update = function (newState) {
@joladev
joladev / nsfw.js
Created October 15, 2013 10:08
Example implementation of an AngularJS state service
angular.module('app.services')
.factory('Nsfw', function ($rootScope) {
'use strict';
var _nsfw = false;
var broadcastNsfw = function (nsfw) {
$rootScope.$broadcast('Nsfw.Update', nsfw);
};
var toggleNsfw = function () {
@joladev
joladev / bind.js
Last active December 25, 2015 18:59
JavaScript Bind 101
// Set up a simple object to use as "context"
var context = { foo: "bar" };
// A function that uses a reference to a variable called "foo".
function returnFoo () {
return this.foo;
}
// This variable does not exist on scope, so is undefined.
returnFoo(); // => undefined
@joladev
joladev / linq.cs
Last active December 25, 2015 20:49
LINQ 101
// Getting some cruft out of the way
public class le{
// Set up a Person class for use in examples.
public class Person{ public string Name { get; set; } }
public static void Main(string[] args){
// A gentle introduction to LINQ, language integrated queries,
// in C#. To start off, let's do some disambiguation.
// This is a lambda expression
@joladev
joladev / randomstring.rs
Last active December 26, 2015 03:09
Attempt at random string generation in Rust
use std::rand;
use std::rand::Rng;
use std::str;
static TARGET: &'static str = "methinks it is like a weasel";
static ALPHABET: &'static [u8] = bytes!("abcdefghijklmnopqrstuvwxyz");
fn random_char() -> u8 {
rand::task_rng().choose(ALPHABET)
@joladev
joladev / weasel.rs
Last active December 26, 2015 13:59
use std::rand;
use std::rand::Rng;
use std::str;
use std::vec;
static MUTATION_RATE: float = 0.04;
static GENERATION_SIZE: int = 100;
static TARGET: &'static [u8] = bytes!("methinks it is like a weasel");
static ALPHABET: &'static [u8] = bytes!("abcdefghijklmnopqrstuvwxyz ");
@joladev
joladev / spoo.cs
Last active December 26, 2015 18:29
OO
ProfileLoaderConfigurationManagerFactory plcmf = new ProfileLoaderConfigurationManagerFactory();
ProfileLoaderConfigurationManager pclm = pclmf.GetProfileLoaderConfigurationManager();
ContextWrapperManagerFactoryProxy cwmfp = ContextWrapperManagerFactoryProxy.GetContextWrapperManager();
ContextWrapper cw = cwmfp.GetContextWrapper(context);
GetProfileLoaderContextApplicationManager gplcam = GetProfileLoaderContextApplicationManagerFactory.GetProfileLoaderContextApplicationManager();
ProfileLoader loader = gplcam.CallGetProfileLoaderWithContextWrapper(pclm, cw);
UserProfile profile = loader.GetUserProfile();
@joladev
joladev / placeholder.js
Last active January 4, 2016 02:59
Faking placeholder in IE8
/**
* Set the "data-placeholder" attribute on your input fields.
* The script is only run if placeholders are not supported.
* Depends on jQuery >= 1.8
**/
(function (window, $) {
var e = document.createElement('input');
if (!('placeholder' in e)) {
$('input[data-placeholder]').each(function (idx, element) {
$(element).val($(element).attr('data-placeholder'));