Skip to content

Instantly share code, notes, and snippets.

Awesome PHP

A list of amazingly awesome PHP libraries, resources and shiny things.

Composer

@ankitdbst
ankitdbst / galerkin.cpp
Created October 4, 2012 09:22
Finite Element Approximation :: Galerkin Method
/**
* Galerkin Method
* Solving for y''+ ay' + by + f(x) = 0
* a, b are constants
* y(u1) = v1, y(u2) = v2 BVP
*/
#include <iostream>
#include <cmath>
using namespace std;
@ankitdbst
ankitdbst / SortLanguageStrings.java
Created August 12, 2012 04:58
Sort the language strings in Moodle repository_plugin.php in lang/
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SortLanguageStrings {
private static final String REGEX = "\\$string\\[\\'(.*)\\'\\].*";
public static void main( String args[] ) {
// Compile pattern
@ankitdbst
ankitdbst / kmp.cpp
Created July 19, 2012 08:56
Knuth Morris Pratt String matching algorithm
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
#define pb push_back
#define forn(a, b) for (int a = 0; a < b; ++a)
#define fore(a, b, c) for (int a = b; a < c; ++a)
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
@ankitdbst
ankitdbst / BinaryAdder.cpp
Created June 26, 2012 16:00
Adds two nums without '+' operation. (Works for positives only)
/*
* Addition using bitwise operations
*/
int binary_adder(int a, int b)
{
int sum = 0, pos = 0;
bool bit = 0, carry = 0;
while(a || b) {
// At each position i bitwise sum is the xor
@ankitdbst
ankitdbst / BinaryTree.cpp
Created May 31, 2012 19:08
Binary Tree class using cpp templates
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <map>
#include <algorithm>