Skip to content

Instantly share code, notes, and snippets.

View alfonmga's full-sized avatar
👁️
What you look for is what you find.

Alfon alfonmga

👁️
What you look for is what you find.
View GitHub Profile
@JCook21
JCook21 / deploy.rb
Created November 11, 2012 18:29
Sample Capifony Deployment script
# Deployment server info
set :application, "APP NAME"
set :domain, "APP DOMAIN NAME"
set :deploy_to, "/path/on/live/server"
set :app_path, "app"
set :web_path, "web"
set :maintenance_basename, "maintenance"
# SCM info
set :repository, "GIT REMOTE REPO URL"
class MoneyType extends AbstractType implements DataMapperInterface
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('amount', 'integer')
->add('currency', 'string')
->setDataMapper($this)
;
}
@h4cc
h4cc / AbstractUser.php
Created January 8, 2014 08:45
JMS\Discriminator Example.
<?php
namespace Entity;
use JMS\Serializer\Annotation as JMS;
/**
* @JMS\Discriminator(field = "type", map = {
* "user": "Entity\User",
* "mod": "Entity\Moderator"
@gerrited
gerrited / GetHashCode32.cs
Last active November 7, 2017 02:48
Microsoft messed up the 64 bit version of GetHashCode. This is a platform independent port of the 32 bit version of Object.GetHashCode based on the unsafe code of Yoni Toledano on StackOverflow (http://stackoverflow.com/a/835571/2132050)
public static class StringExt
{
public static int GetHashCode32(this string s)
{
var chars = s.ToCharArray();
var lastCharInd = chars.Length - 1;
var num1 = 0x15051505;
var num2 = num1;
var ind = 0;
while (ind <= lastCharInd)
@atorralb
atorralb / iterate_through_pagination_in_nightmare.js
Created April 9, 2016 00:16
iterate through a pagination site with nightmarejs
var Nightmare = require('nightmare');
var vo = require('vo');
vo(run)(function(err, result) {
if (err) throw err;
});
fu
@stubailo
stubailo / apollo-fetch.js
Last active December 1, 2018 15:54
Call a GraphQL API with apollo-fetch
const { createApolloFetch } = require('apollo-fetch');
const fetch = createApolloFetch({
uri: 'https://1jzxrj179.lp.gql.zone/graphql',
});
fetch({
query: '{ posts { title }}',
}).then(res => {
console.log(res.data);
@DimitarChristoff
DimitarChristoff / store-trap.html
Created October 22, 2016 22:50
chrome store abuse
<!-- view-source:http://cofinsa.info/helloworld.php?city=GB&clickid=wOG4PFS3EJJ786J0H5TOVOG4 -->
<!--<script>if(history.replaceState) history.replaceState({}, "", "/");</script>-->
<script>confirm('Add Extension to Leave');</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
@havvg
havvg / StreetAddressType.php
Created December 17, 2012 13:58
Symfony2 Forms: dynamic "NotBlank"-constraints
<?php
namespace Ormigo\Bundle\OrmigoBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Ormigo\Bundle\OrmigoBundle\Form\DataTransformer\StreetAddressModelTransformer;
use Ormigo\Bundle\OrmigoBundle\Form\Validator\StreetAddressValidator;
import ApolloClient from 'apollo-boost';
const client = new ApolloClient({
uri: '<your graphql endpoint>',
// Apollo Boost allows you to specify a custom error link for your client
onError: ({ graphQLErrors, networkError, operation, forward }) => {
if (graphQLErrors) {
for (let err of graphQLErrors) {
// handle errors differently based on its error code
switch (err.extensions.code) {
@raphaelstolt
raphaelstolt / pre-commit
Created September 20, 2010 21:35
A pre-commit for running PHPUnit
#!/usr/bin/php
<?php
printf("%sGit pre-commit hook %1\$s", PHP_EOL);
$projectName = basename(getcwd());
exec('phpunit --configuration phpunit.xml', $output, $returnCode); // Assuming cwd here
if ($returnCode !== 0) {
$minimalTestSummary = array_pop($output);
printf("Test suite for %s failed: ", $projectName);
printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
return false; // exit(1);